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