Euclid's algorithm 2/22/2011 Just for fun: var _gcd = function(a, b) { return ( b == 0 ) ? a : _gcd( b, a%b ); }