Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

151
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!