Tell us what’s happening:
Hi Everyone,
My code passes for Smallest Common Multiple except for the last two tests. I ran my code at repl.it and the code passes both those cases there so I’m not sure why it isn’t passing on FCC. Can anyone help? I’ve reset the code a couple times and it still isn’t passing.
Your code so far
function smallestCommons(arr) {
arr.sort(function(a, b) {return a - b});
let least = arr[0];
let greatest = arr[1];
let numsBetween = [];
for (let b = least; b <= greatest; b++) {
numsBetween.push(b);
}
for (let i = least; true; i++) {
if (i % least === 0 && i % greatest === 0) {
if (numsBetween.every(ele => i % ele === 0)) {
return i;
}
}
}
}
function smallestCommons(arr) {
arr.sort(function(a, b) {return a - b});
let least = arr[0];
let greatest = arr[1];
let numsBetween = [];
for (let b = least; b <= greatest; b++) {
numsBetween.push(b);
}
for (let i = least; true; i++) {
if (i % least === 0 && i % greatest === 0) {
if (numsBetween.every(ele => i % ele === 0)) {
return i;
}
}
}
}
smallestCommons([1,5]);
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36
.
Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/smallest-common-multiple