My code for the Smallest Common Multiple challenge works fine with smaller numbers, but for some reason when larger numbers are used, it tells me that I have a possible infinite loop. I think the code should work with any set of numbers. Why would there be an infinite loop with larger numbers? Like when I pass 1 and 11 it works fine, but when I pass 1 and 12, it says there’s a possible infinite loop. Can anyone offer any words of advice for this noob?
**Your code so far**
function smallestCommons(arr) {
if (arr[0] > arr[1]) {
arr = [arr[1], arr[0]];
}
let newArr = [];
for (let i = arr[0]; i <= arr[1]; i++) {
newArr.push(i);
}
let x = newArr.length - 1;
let num = newArr[x] ;
let testArr = [-1];
while (testArr.some(x => x !== 0)) {
if (testArr[0] === -1) {
testArr.pop();
}
testArr = [];
for (let i = 0; i < newArr.length; i++) {
testArr.push(num % newArr[i]);
}
num++;
}
num = num - 1;
return num;
}
console.log(smallestCommons([1, 6]));
**Your browser information:**
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/99.0.4844.84 Safari/537.36
Challenge: Smallest Common Multiple
Link to the challenge: