Skip to content

Commit aba0cb2

Browse files
authored
Merge pull request AllAlgorithms#27 from Ditobaskoro/gcd
create greatestCommonDivisor
2 parents 370b9ef + 2e9bc33 commit aba0cb2

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

math/greatestCommonDivisor.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// JavaScript implementation of greatest common divisor of two positive number
2+
3+
let gcd = function(a, b) {
4+
if (!b) {
5+
return a;
6+
}
7+
8+
return gcd(b, a % b);
9+
};
10+
11+
console.log(gcd(2154, 458));

0 commit comments

Comments
 (0)