Hello,
I wrote a script for the Smallest Common Multiple project but it seems that isn’t working for bigger numbers.
Probably because the loop is taking too long.
Here is to code:
function smallestCommons(arr) {
arr.sort(function(a,b){
return a-b;
});
var s = arr[0];
var b = arr[1];
var idx = 1;
var found = false;
while(!found){
var k = 0;
for(s = arr[0]; s<=b; s++){
if(idx%s === 0)
k++;
}
if(k === b)
break;
idx++;
}
return idx;
}
smallestCommons([1,13]);
I know my logic is wrong. But this is what I could get up to this point!
I know it works, but it gets stuck in the middle somewhere xD.