Greatest common divisor: Difference between revisions

add JavaScript
(Added Perl 6.)
(add JavaScript)
Line 490:
if(a > b) return gcd(b, a % b);
return gcd(a, b % a);
}</lang>
 
=={{header|JavaScript}}==
Iterative.
<lang javascript>function gcd(a,b) {
if (a < 0) a = -a;
if (b < 0) b = -b;
if (b > a) {var temp = a; a = b; b = temp;}
while (true) {
a %= b;
if (a == 0) return b;
b %= a;
if (b == 0) return a;
}
}</lang>
 
Anonymous user