Hey guys (and girls)…
I have a code:
function smallestCommons(arr) {
arr = arr.sort((a, b) => a < b);
var arr2 = [];
var count = 0;
for(let i = 0; i <= arr[0] - arr[1]; i++) {
arr2.push(arr[0] - i);
}
for(let i = arr2[0]; i < 10000; i += arr2[0]) {
for(let j = 0; j < arr2.length; j++) {
if(i % arr2[j] !== 0) {
count = 0;
break;
}else if(i % arr2[j] === 0) {
count ++;
if(count === arr2.length) {
return i;
}
}
}
}
}
smallestCommons([1,5]);
and I know putting 10000 in a for loop isn’t right but i did it just to experiment and the code works well if result isn’t bigger than 10000 (first 3 tests). How to set that condition in order to avoid infinite loop but get all test correct?