Anonymous user
Greatest common divisor: Difference between revisions
→{{header|JavaScript}} Changed to Math.max() instead of manual swap. Changed formatting to match convention. Whitespace and readability changes.
(→{{header|PowerShell}}: port short Python implementation) |
|||
Line 1,375:
=={{header|JavaScript}}==
Iterative
<lang javascript>function gcd(a,b) {
a =
b =
if (b > a) {var temp = a; a = b; b = temp;}▼
if (b
var temp
if (b == 0) return a;▼
▲ }
if (a === 0) { return b; }
}</lang>
Recursive.
<lang javascript>function gcd_rec(a, b) {
▲ if (b) {
▲ } else {
▲ return Math.abs(a);
▲ }
}</lang>
<lang javascript>function GCD(
y
▲ }
}
x += y;
}
return x;
}
/
=={{header|Joy}}==
|