function smallestCommons(arr) {
var arr1=[];
arr.sort(function(a,b){//sorting argument array
return a-b;
});
for(var i=arr[0];i<=arr[1];i++){//getting a range between the two given numbers of array i.e[1,5]=[1,2,3,4,5]
arr1.push(i);
}
var j=1;
var result=[];
var num;
while(result.length==0){//keep looping until we dont get LCM in result array
num=arr1[0]*j;//Getting the number in num which is to be checked as LCM of all numbers of arr1
for(var k=0;k<arr1.length;k++){//checking if num is LCM for all arr1 numbers
if(num%arr1[k]!=0){//break the loop if num is not fully devided by any arr1 numbers
break;
}
if(num%arr1[k]==0){//iteratively checking if num is LCM of all arr1 numbers
if(k<arr1.length-1){//only continue to check next arr1 number if it is not last
continue;
}
result.push(num);//push the LCM in result if loop never breaks
}
}
j++; //if loop breaks increment j to get next number in num which is to be checked
}
return result[0];
}
smallestCommons([23,18]);
Program is to find the smallest common multiple of the provided parameters that can be evenly divided by both, as well as by all sequential numbers in the range between these parameters. My code runs great every where including mozilla developer tool and sublimetext 3 for all test cases. But in freecodecamp results it is showing infinite loop for [1,13] case at line 14 i.e “num=arr1[0]*j”. I couldnt figure out the problem kindly help me out.