Tell us what’s happening:
Please can someone explain why my while loop does not evaluate to false
Your code so far
function smallestCommons(arr) {
const min = Math.min(...arr);
const max = Math.max(...arr);
const array = [];
let count = 1;
for (let i = min; i <= max; i++) {
array.push(i);
}
const dup = array.slice(); // copy array to dup
while (dup.every((elem) => dup[dup.length - 1] % elem === 0) == false) {
for (let i = 0; i < array.length; i++) {
dup[i] = array[i] * count
}
console.log(dup)
count++
}
return dup[dup.length - 1];
}
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/113.0.0.0 Safari/537.36
Challenge: Intermediate Algorithm Scripting - Smallest Common Multiple
Link to the challenge: