Skip to content

Instantly share code, notes, and snippets.

@toboid
Created November 23, 2025 11:25
Show Gist options
  • Select an option

  • Save toboid/51e036139fd55663a6d03d87604bdb5e to your computer and use it in GitHub Desktop.

Select an option

Save toboid/51e036139fd55663a6d03d87604bdb5e to your computer and use it in GitHub Desktop.
Greatest common divisor in JavaScript using euclidean algorithm
function gcd(a, b) {
while (b > 0) {
[a, b] = [b, a % b]
}
return a;
}
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