update snippets 1-15

This commit is contained in:
Stefan Feješ
2017-12-25 13:59:23 +01:00
committed by Agamemnon Zorbas
parent aaeb11616c
commit 5036ff5781
15 changed files with 72 additions and 31 deletions

View File

@ -7,9 +7,12 @@ Use `Array.reduce()` and the `lcm` formula (uses recursion) to calculate the low
```js
const arrayLcm = 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));
};
// arrayLcm([1,2,3,4,5]) -> 60
// arrayLcm([4,8,12]) -> 24
const lcm = (x, y) => (x*y)/gcd(x, y);
return arr.reduce((a,b) => lcm(a,b));
}
```
```js
arrayLcm([1,2,3,4,5]) -> 60
arrayLcm([4,8,12]) -> 24
```