Tell us what’s happening:
This code works! At least, it does on codepen. Why won’t it work on freeCodeCamp? Is there a timeout?
Your code so far
function smallestCommons(arr) {
let sequence = [];
// sort array
arr.sort(function(a, b) {
if (a > b) {
return 1;
} else {
return -1;
}
});
// create array of range
for (let i = arr[0]; i <= arr[1]; i++) {
sequence.push(i);
}
let j = arr[1];
while(!sequence.every(function(elem) {
return j % elem == 0;
})) {
j += 1;
}
console.log(j);
return j;
}
smallestCommons([23, 18]);
Your browser information:
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.100 Safari/537.36
.
Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/smallest-common-multiple