I’m on Smallest Common Multiple and I’m pretty sure the code should work but it keeps saying there’s an infinite loop in the while statement.
Could someone please explain to me what the issue is?
function smallestCommons(arr) {
var arr1 = arr.sort(function(a,b){
return a-b;
});
var arr2 = [];
var loopStop = 20;
var ans = 0;
for (var i = arr1[0]; i <= arr[1];i++) {
arr2.push(i);
}
while (loopStop == 20) {
for (var n = arr2[0]; n <= arr2[arr2.length-1]; n++) {
if (ans % n !== 0) {
ans++;
break;
}
else if (n == arr2[arr2.length-1]) {
loopStop = 21;
}
}
}
return ans;
}
smallestCommons([23,18]);