This commit is contained in:
Angelos Chalaris
2017-12-27 11:02:46 +02:00
parent 0d9b02a3cb
commit b74eb9d9bd
45 changed files with 89 additions and 91 deletions

View File

@ -5,11 +5,11 @@ 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 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));
}
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
```