Tell us what’s happening:
I debugged the code in Chrome Inspect element and the code passes all the test cases mentioned below the question. When I run the code in Chrome, All the answers match the expected answers, however when I run the code in FreeCodeCamp’s test environment, the last test case fails for some reason. Is this a known problem ?
I do not see any flaw in my algorithm. Please feel free to correct me if I am wrong.
Note: The answer to the last test case smallestCommons([23, 18]) is 6056820, which is what my code achieves too, however for some reason the test case fails in FreeCodeCamp’s test environment.
Your code so far
function smallestCommons(arr) {
arr.sort();
var flag = 1, num = arr[1];
while(flag != 2){
for(var i = arr[0]; i <= arr[1]; i++){
if(num%i != 0){
flag = 0;
break;
}
}
if(flag){
flag = 2;
}
else{
flag = 1;
num++;
}
}
return num;
}
smallestCommons([1,5]);
Your browser information:
Your Browser User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.113 Safari/537.36
.
Link to the challenge: