Archive, multitagging, cleanup

Cleaned up the current snippets for consistency and minor problems, added multiple tags to most of them, archived a few.
This commit is contained in:
Angelos Chalaris
2018-01-05 16:33:54 +02:00
parent f91b28d3fc
commit 0425ebefe7
55 changed files with 2650 additions and 2682 deletions

View File

@ -1,6 +1,6 @@
### lcm
Returns the least common multiple of two or more numbers/arrays.
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.
@ -9,11 +9,11 @@ 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 [].concat(...arr).reduce((a, b) => _lcm(a, b));
return [...arr].reduce((a, b) => _lcm(a, b));
};
```
```js
lcm(12, 7); // 84
lcm([1, 3, 4], 5); // 60
lcm(...[1, 3, 4, 5]); // 60
```