Hello! I think that the logic of my code is correct (also the results), but over a certain number i get the error “InternalError: too much recursion”.
Why? arr=[1,12] is still ok, arr=[1,13] crashes…
function smallestCommons(arr) {
if (arr[1]<arr[0]){ // reverse the array to order the numbers
arr.reverse(); //from smallest to bigger
}
var remainder;
var a=arr[0];
var b=arr[1]; // b will be tested, if it can not be divided by all intermediate
// numbers, will be added himself and tested again
loop();
function loop(){
remainder=0;
for (var i=arr[0];i<arr[1];i++){
remainder=b%i;
if(remainder!==0){
b+=arr[1];
loop();
}
}
}
return b;
}
smallestCommons([1,12]);