indent the code correctly
This commit is contained in:
@ -1,10 +1,10 @@
|
|||||||
|
|
||||||
### gcdOfArray
|
### gcdOfArray
|
||||||
|
|
||||||
It finds the GCD of all the numbers in an array by using `array.reduce` and the fact that `gcd(a,b,c) = gcd(gcd(a,b),c)`
|
It finds the GCD of all the numbers in an array by using `Array.reduce()` and the fact that `gcd(a,b,c) = gcd(gcd(a,b),c)`
|
||||||
|
|
||||||
```js
|
```js
|
||||||
const gcdOfArray = arr =>
|
const gcdOfArray = arr =>{
|
||||||
{
|
|
||||||
const gcd = (x, y) => !y ? x : gcd(y, x % y);
|
const gcd = (x, y) => !y ? x : gcd(y, x % y);
|
||||||
return arr.reduce((a,b) => gcd(a,b))
|
return arr.reduce((a,b) => gcd(a,b))
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user