 # Smallest Common Multiple Help!

So I created these functions to solve this algorithm…It really took me a while to figure it out but I tested it on my own custom HTML/JS and i got all the answers, yet when i test it on FCC’s it says I have an infinite loop…Can some one help me please! This one has really kicked my butt!

``````function lc(num1,num2){
var boo = false;
var i = 1;
while(!boo){
if(i % num1 === 0){
if(i % num2 === 0){
return i;
}
}
i++;
}
}

function sortArr(arr) {
arr = arr.sort(function(a,b){return a-b;});
var j = 0;
for(var i=0; i < arr[arr.length-1]; i++ ){
if(i > arr[j]){
arr.push(i);
arr = arr.sort(function(a,b){return a-b;});
j++;
}

}

return arr;
}

function smallestCommons(arr){
arr = sortArr(arr);
var result = lc(arr[arr.length-2], arr[arr.length-1]);
for(var i=arr.length-3; i >= 0; i--){
if(arr[i] === undefined){
return result;
}
result = lc(result, arr[i]);
}

return result;
}

// lc(18,2018940)

smallestCommons([23, 18]);``````

The infinite loop detection is based off of how long it takes your code to run. After a certain amount of time it kills the process and sends up the warning. You can turn the infinite loop protection off:

Generally, be cautious about doing this. Infinite loops are a common problem (which is why the check exists). On this particular challenge though it is very common for campers to come up with solutions that take long enough for the infinite loop protector to yell at them.