How to find the smallest number that is evenly divisible by all of the numbers from 1 to 20 in Node.js

1 Answer

0 votes
function LMC(a, b) {
    let lmc = (a > b) ? a : b;
    
    while (true) {
        if (lmc % a == 0 && lmc % b == 0) {
            return lmc;
        }
        lmc++;
    }
}
        
let result = 1;

for (let i = 1; i <= 20; i++) {
    result = LMC(result, i);
}

console.log(result);




/*
run:

232792560

*/

 



answered Oct 20, 2023 by avibootz
...