Can’t seem to figure out what is going wrong. I pass all the tests except for the last one [23,18].
function smallestCommons(arr) {
var range = [], i, checker;
//sort by smallest to largest number;
i = arr.sort(function (a, b) {
return a - b;
});
var j = 1;
for(var k = i[0]; k <= i[1]; k++){
if((i[1] * j) % k === 0){
checker = (i[1]) * j;
} else{
k = i[0];
j++;
}
}
return checker;
}
The number it gives me is divisible by all of the numbers in the range EXCEPT 18 - but I don’t understand why as 18 should be the first number it performs the check on…