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

154
Visualizações
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 à 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