```
function smallestCommons(arr) {
// sort the arr argument in ascending order if not
arr = arr.sort(function(a, b) {
return a-b;
});
var arrs = [];
var min = arr[0];
var max = arr[1];
var flag = 0;
var times = 1;
init(arrs, min, max);
while (times < 100) {
flag = check(arrs, min, max, times, flag);
if (flag == 1) {
return arrs[0][times-1];
}
else {
times++;
createMultiple(arrs, min, max, times);
}
}
return arrs;
}
// all defined seperate functions..................................
// initiate the nested array to hold the multiples for all numbers
function init(arrs, min, max) {
for (var i = min; i <= max; i++) {
arrs[i-min] = [i];
}
}
// check if least common mulitples; if not, generate more multiples
function check(arrs, min, max, times, flag) {
var count = 0;
for (var x1 = 0; x1 <= max-min; x1++) {
if (arrs[x1].indexOf(arrs[0][times-1]) < 0) {
break;
}
else {
count++;
}
}
if (count > max-min) {
flag = 1;
}
return flag;
}
// generate multiples
function createMultiple(arrs, min, max, times) {
for (var num = min; num <= max; num++) {
arrs[num-min].push(num * times);
}
return arrs;
}
// test
smallestCommons([1,5]);
```

For the purpose of testing my code, I try `smallestCommons([1,5]);`

first. Since, the smallest common multiple for array range of [1, 5] is 60, which has 12 times multiplication. I provide the `while(times < 100)`

, and it outputs correctly as: 60. But for bigger number like `smallestCommons([1, 13])`

, if I run `while(times < 360361)`

, my computer run nearly ten seconds, and pop out: `Error: potential infinite loop at line 20....`

., which indicats `while()`

loop. Sure, same result found when use `while(true)`

. Could anyone provide some hints about this problem? Thanks in advance.