Files
30-seconds-of-code/snippets/greatest-common-divisor-(GCD).md
Angelos Chalaris d9c4f9234f Formatted snippets
Consistency in headings.
2017-11-30 19:17:33 +02:00

240 B

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.

var gcd = (x , y) => !y ? x : gcd(y, x % y);