Files
30-seconds-of-code/snippets/greatest-common-divisor-(GCD).md
2017-12-12 07:11:37 -05:00

10 lines
242 B
Markdown

### Greatest common divisor (GCD)
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 = (x , y) => !y ? x : gcd(y, x % y);
```