hello.
I feel really stupid asking for help on this because it should be really simple, but I can’t find the reason why this code is not behaving like I think it should, heres the code:
function smallestCommons(arr) {
arr.sort( (a,b) => a-b);
let flag = true;
let count = arr[1];
while (flag == true) {
count += 1;
for (let i=arr[0]; i <= arr[1]; i++) {
if (count % i != 0) {
}
if (i = arr[1] && count % i == 0) {
flag = false;
console.log(flag);
}
}
}
console.log(count);
return count;
}
smallestCommons([1,5]);
If you run the code you can see the console is printing false
, then why is the while
loop not ending if the while (flag == true)
condition is not being met?