Created
January 27, 2012 21:16
-
-
Save riovv/1690965 to your computer and use it in GitHub Desktop.
JavaScript: Greatest Common Divisor
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
// JavaScript: Greatest Common Divisor | |
var gcd = function (n, m) { | |
var r = 0; | |
while (n !== 0) { | |
r = m % n; | |
m = n; | |
n = r; | |
} | |
return m; | |
}; |
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
var gcd = function (n, m) { | |
var r = 0; | |
while (n !== 0) { | |
r = m % n; | |
m = n; | |
n = r; | |
} | |
return m; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
var gcd = function(a, b) {
if ( ! b) {
return a;
}
};