Files
30-seconds-of-code/test/lcm/lcm.js
2018-01-09 06:09:49 -05:00

5 lines
169 B
JavaScript

module.exports = (...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));
};