add snippet toKebabCase

This commit is contained in:
Rohit Tanwar
2017-12-22 22:44:51 +05:30
parent 1b34907f96
commit 144894cca5
4 changed files with 22 additions and 9 deletions

View File

@ -1,16 +1,12 @@
### gcd
Calculates the greatest common divisor between two or more numbers numbers.
Calculates the greatest common divisor between two numbers.
The helper function uses recursion.
The helper case takes two arguments x and y
Use recursion.
Base case is when `y` equals `0`. In this case, return `x`.
Otherwise, return the GCD of `y` and the remainder of the division `x/y`.
```js
const gcd = (...arr) => {
const gcdHelper = (x, y) => !y ? x : gcd(y, x % y);
return arr.reduce((a,b) => gcdHelper(a,b))
}
const gcd = (x, y) => !y ? x : gcd(y, x % y);
// gcd (8, 36) -> 4
```