Tell us what’s happening:
Hello, all tests except the last one ( smallestMult(20)) are giving the correct answer in the FreeCodeCamp terminal(?). It says: smallestMult(20) should return 232792560
But if I run the code on the VS Vode terminal through node, the answer returned there is correct (returned after ~ 2seconds).
I must be overlooking something.
Thanks for any help and sorry for the messy code I am not really familiar with JavaScript. Any advice is welcome.
Your code so far
function smallestMult(n) {
const lst = [];
const divisors = new Set();
for (let a = 2; a <= n; a++) {
lst.push(a);
}
let temp_lst = [];
for (let number of lst) {
temp_lst = [];
for (let b of lst) {
if (b % number === 0) {
temp_lst.push(b);
}
}
divisors.add(Math.max(temp_lst));
}
divisors.delete(NaN);
let i = n;
while (true) {
let divisible = true;
for (let d of divisors) {
if (i % d != 0) {
divisible = false;
break;
}
}
if (divisible) {
return i;
}
i += 1;
}
}
smallestMult(20);
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/112.0
Challenge: Project Euler Problems 1 to 100 - Problem 5: Smallest multiple
Link to the challenge: