This code will pass all test cases except for the final test case - [23,18]. Can anyone explain why it isn’t working?
Your code so far
function smallestCommons(arr) {
var max = Math.max(arr[0],arr[1]);
var min = Math.min(arr[0],arr[1]);
var current = max;
for(var i = max; i > min; i--) {
if(current % i != 0) {
current += max;
i = max;
}
}
//console.log(current);
return current;
}
smallestCommons([18, 23]);
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36.
Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/smallest-common-multiple