Merge pull request #197 from Pl4gue/patch-1

Create least-common-multiple-(LCM).md
This commit is contained in:
Angelos Chalaris
2017-12-17 11:27:02 +02:00
committed by GitHub

View File

@ -0,0 +1,12 @@
### Least common multiple (LCM)
Use the greatest common divisor (GCD) formula and `Math.abs()` to determine the least common multiple.
The GCD formula uses recursion.
```js
const lcm = (x,y) => {
const gcd = (x, y) => !y ? x : gcd(y, x % y);
return Math.abs(x*y)/(gcd(x,y));
};
// lcm(12,7) -> 84
```