What is your hint or solution suggestion?
This can be done using ES6. Use the reduce()
method to find the GCD of all numbers in the sequence. The LCM can then be found as n!/gcd
using the reducer.
Solution 1
function smallestMult(n) {
const gcd = (a, b) => a ? gcd(b % a, a) : b;
const lcm = (a, b) => a * b / gcd(a, b);
return [...Array(n+1).keys()].slice(1).reduce(lcm);
}
Challenge: Project Euler: Problem 5: Smallest multiple
Link to the challenge: