update snippets 1-15

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

View File

@ -7,8 +7,11 @@ Use `Array.reduce()` and the `gcd` formula (uses recursion) to calculate the gre
```js
const arrayGcd = arr => {
const gcd = (x, y) => !y ? x : gcd(y, x % y);
return arr.reduce((a, b) => gcd(a, b));
};
// arrayGcd([1,2,3,4,5]) -> 1
// arrayGcd([4,8,12]) -> 4
return arr.reduce((a,b) => gcd(a,b));
}
```
```js
arrayGcd([1,2,3,4,5]) -> 1
arrayGcd([4,8,12]) -> 4
```