Skip to content

Instantly share code, notes, and snippets.

@JiLiZART
Last active June 26, 2016 19:48
Show Gist options
  • Save JiLiZART/0628f7d7bb04b3d785dddcf2beb3d8d0 to your computer and use it in GitHub Desktop.
Save JiLiZART/0628f7d7bb04b3d785dddcf2beb3d8d0 to your computer and use it in GitHub Desktop.
function gcd(a, b) {
if (a < 0 || b < 0) throw Error ('positive numbers only');
if (a === 0 || b === 0)
return Math.max(a, b);
else if (a >= b)
return gcd(a % b, b);
else
return gcd(a, b % a);
}
console.log(gcd(15, 10));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment