Programming-Idioms

History of Idiom 74 > diff from v23 to v24

Edit summary for version 24 :
New JS implementation by user [1.7.4]

Version 23

2018-09-06, 20:03:38

Version 24

2019-01-24, 10:00:26

Idiom #74 Compute GCD

Compute the greatest common divisor x of big integers a and b. Use an integer type able to handle huge numbers.

Idiom #74 Compute GCD

Compute the greatest common divisor x of big integers a and b. Use an integer type able to handle huge numbers.

Code
const gcd = (a, b) => !b ? a : gcd (b, a % b)
Comments bubble
Warning: This implementation is not the most efficient. Figure out a more efficient way to do this if you're up for it!
Origin
https://stackoverflow.com/a/17445304/10871673