Tell us what’s happening:
my code works for the 4 but only fails in [25,18].
When I copy and paste [25.18] to the console. it says this could create an infinite loop/
I can’t figure out why it works for [5,1] but not for [25,18].
Is it because it goes througth the loop so many times even though it’s not infinite loop?
Your code so far
function smallestCommons(arr) {
var num;
var i;
var temp=[];
if(arr[0]<arr[1]){
for(num=arr[1];num<1000000;num++){
for(i=arr[0];i<=arr[1];i++){
if( (num % i) !=0)
break;
}
if( (num % i)==0 )
return num;
}
}
if(arr[1]<arr[0]){
for(num=arr[0];num<6500000;num++){
for(i=arr[1];i<=arr[0];i++){
if( (num % i) !=0)
break;
}
if( (num % i)==0 )
return num;
}
}
}
smallestCommons([1, 13]);
Your browser information:
Your Browser User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36
.
Link to the challenge: