Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

Least common multiple from array

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));
};
Source by www.30secondsofcode.org #
 
PREVIOUS NEXT
Tagged: #Least #common #multiple #array
ADD COMMENT
Topic
Name
2+1 =