lcm(x, y) = x * y / gcd(x, y)
to determine the least common multiple.const lcm = (...arr) => {
const gcd = (x, y) => (!y ? x : gcd(y, x % y));
const _lcm = (x, y) => (x * y) / gcd(x, y);
return [...arr].reduce((a, b) => _lcm(a, b));
};
lcm(12, 7); // 84 lcm(...[1, 3, 4, 5]); // 60
Subscribe to get resources directly to your inbox. You won't receive any spam! ✌️