Logo

Programming-Idioms

History of Idiom 74 > diff from v24 to v25

Edit summary for version 25 by 1.7.4:
[JS] Clarified program

Version 24

2019-01-24, 10:00:26

Version 25

2019-01-25, 11:48:54

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)
Code
const gcd = (a, b) => b === 0 ? 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!
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
Origin
https://stackoverflow.com/a/17445304/10871673