diff --git a/README.md b/README.md index b5e36be96..bf44e4cb0 100644 --- a/README.md +++ b/README.md @@ -3178,7 +3178,7 @@ isPrime(11); // true Returns the least common multiple of two or more numbers. -Use the greatest common divisor (GCD) formula and `Math.abs()` to determine the least common multiple. +Use the greatest common divisor (GCD) formula and the fact that `lcm(x,y) = x * y / gcd(x,y)` to determine the least common multiple. The GCD formula uses recursion. ```js diff --git a/docs/index.html b/docs/index.html index 8e66ca74e..d32d03cc4 100644 --- a/docs/index.html +++ b/docs/index.html @@ -667,7 +667,7 @@ own individual rating by supplying it as the third argument. return num >= 2; };
isPrime(11); // true -
Returns the least common multiple of two or more numbers.
Use the greatest common divisor (GCD) formula and Math.abs() to determine the least common multiple. The GCD formula uses recursion.
const lcm = (...arr) => { +
Returns the least common multiple of two or more numbers.
Use the greatest common divisor (GCD) formula and the fact that lcm(x,y) = x * y / gcd(x,y) to determine the least common multiple. The GCD formula uses recursion.
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));