Fully renamed and updated everything, tagged, built
This commit is contained in:
12
snippets/gcd.md
Normal file
12
snippets/gcd.md
Normal file
@ -0,0 +1,12 @@
|
||||
### gcd
|
||||
|
||||
Calculates the greatest common divisor between two numbers.
|
||||
|
||||
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);
|
||||
// gcd (8, 36) -> 4
|
||||
```
|
||||
Reference in New Issue
Block a user