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

153
Vistas
LCM function exercise

so the exercise i got was to come up with function that returns least common multiple. We were told we would like to and should use Do...while loop while at it. After some trial and error, i came up with this:

const lcm = function(a, b) {
let min = 1;

while (true) {
  if(min % a === 0 && min % b === 0) {
    return min;
    }
  min++;
  }
}

As you can see, i completely omitted do...while loop as we were adviced. I have tried several input combinations and they all checked out and it seems it works. But then however, i also decided to google some other solutions and basically most of them looks like more complex and longer code than this one and i wonder why.

Does this mean that at some point, with certain inputs/parameters, the code would break ? Or endless loop would occur ? Could you please check this out someone ? thanks

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