Hey everyone,
I’m having a weird issue on the Smallest Common Multiple Assignment. Here’s my code:
function smallestCommons(arr) {
if(arr[0] > arr[1]) {
var temp = arr[0];
arr[0] = arr[1];
arr[1] = temp;
}
for(var count = arr[1]; count < 10000000; count++) {
var divisible = true;
for(var count2 = arr[0]; count2 <= arr[1]; count2++) {
if(count%count2 != 0) {
divisible = false;
break;
}
}
if(divisible == true) {
arr = count;
break;
}
}
return arr;
}
smallestCommons([1,5]);
The test cases are as follows:
smallestCommons([1, 5]) should return a number.
smallestCommons([1, 5]) should return 60.
smallestCommons([5, 1]) should return 60.
smallestCommons([1, 13]) should return 360360.
smallestCommons([23, 18]) should return 6056820.
Everything works except the last test case. When I plug that test case’s numbers into the program it gives me a potential infinite loop error. How is it possible that I have a potential infinite loop for only one test case?