Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

221
Visualizações
Finding Smallest Common multiple in the given range of numbers in Java Script

Hi it's my first question here, Find the smallest common multiple of the provided parameters that can be evenly divided by both, as well as by all sequential numbers in the range between these parameters.

The range will be an array of two numbers that will not necessarily be in numerical order.

For example, if given 1 and 3, find the smallest common multiple of both 1 and 3 that is also evenly divisible by all numbers between 1 and 3. The answer here would be 6.

Ive tried the following code but I dont know why its not working...

 function smallestCommons(arr) {
  arr.sort(function(a,b){return a-b});//sorts the array
  /* Prints a sorted Array*/
  let sortArr=[];
  for(let i=arr[0];i<=arr[1];i++){
    sortArr.push(i);
  }

  /*Find Largest Possible LCM*/
  let largeCM=1;
  for(let i=0;i<sortArr.length;i++){
    largeCM*=sortArr[i];
  }

/*Array of multiples of last element of SortArray*/
let newArr=[];
  for(let i=arr[1];i<=largeCM;i+=arr[1]){
    newArr.push(i);
  }

/*Finding the final final possible values*/
  for(let i=arr[0];i<=arr[1];i++){
    for(let j=0;j<newArr.length;j++){
      if(newArr[j]%i !=0){
        newArr.splice(j,1);
      }
    }
  }

/*Finding the LCM*/
  return newArr[0];
}

smallestCommons([1,5]);
about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda