Travis build: 47

This commit is contained in:
Pl4gue
2017-12-21 15:51:36 +00:00
parent 906c9548d7
commit 90243d686e
2 changed files with 31 additions and 0 deletions

View File

@ -12,6 +12,7 @@
### Array
* [`arrayGcd`](#arraygcd)
* [`arrayLcm`](#arraylcm)
* [`arrayMax`](#arraymax)
* [`arrayMin`](#arraymin)
* [`chunk`](#chunk)
@ -175,6 +176,24 @@ const arrayGcd = arr =>{
[⬆ back to top](#table-of-contents)
### arrayLcm
Calculates the lowest common multiple (lcm) of an array of numbers.
Use `Array.reduce()` and the `lcm` formula (uses recursion) to calculate the lowest common multiple of an array of numbers.
```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
```
[⬆ back to top](#table-of-contents)
### arrayMax
Returns the maximum value in an array.