Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

223
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda