Last active
June 26, 2016 19:48
-
-
Save JiLiZART/0628f7d7bb04b3d785dddcf2beb3d8d0 to your computer and use it in GitHub Desktop.
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 (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