Created
November 23, 2025 11:25
-
-
Save toboid/51e036139fd55663a6d03d87604bdb5e to your computer and use it in GitHub Desktop.
Greatest common divisor in JavaScript using euclidean algorithm
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function gcd(a, b) { | |
| while (b > 0) { | |
| [a, b] = [b, a % b] | |
| } | |
| return a; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function gcd(a, b) { | |
| if (b === 0) { | |
| return a; | |
| } | |
| return gcd(b, a % b); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment