Skip to content

Commit 3253cbb

Browse files
new commit
1 parent 26d3928 commit 3253cbb

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

32_gcdTwoPositiveNumbers.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
function gcd(a, b) {
2+
// write your code here
3+
if (a === 0) {
4+
return b;
5+
}
6+
if (b === 0) {
7+
return a;
8+
}
9+
if (a === b) {
10+
return a;
11+
}
12+
if (a > b) {
13+
return gcd(a - b, b);
14+
} else {
15+
return gcd(a, b - a);
16+
}
17+
}
18+
19+
const a = 2154;
20+
const b = 458;
21+
22+
console.log("The GCD of " + a + " ", b + " is " + gcd(a, b));

0 commit comments

Comments
 (0)