Skip to content

Instantly share code, notes, and snippets.

@riovv
Created January 27, 2012 21:16
Show Gist options
  • Save riovv/1690965 to your computer and use it in GitHub Desktop.
Save riovv/1690965 to your computer and use it in GitHub Desktop.
JavaScript: Greatest Common Divisor
// JavaScript: Greatest Common Divisor
var gcd = function (n, m) {
var r = 0;
while (n !== 0) {
r = m % n;
m = n;
n = r;
}
return m;
};
var gcd = function (n, m) {
var r = 0;
while (n !== 0) {
r = m % n;
m = n;
n = r;
}
return m;
};
@paywatch
Copy link

var gcd = function(a, b) {
if ( ! b) {
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