We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent d22738d commit 101137eCopy full SHA for 101137e
Number Theory/GCD/es6/gcd.js
@@ -0,0 +1,19 @@
1
+/* Greatest Common Divisor (GCD) Finding in JavaScript */
2
+
3
+const gcd = (a, b) => {
4
+ while (true) {
5
+ var remainder = a%b;
6
+ if (remainder === 0) return b;
7
8
+ a = b;
9
+ b = remainder;
10
+ }
11
+}
12
13
+//A recursive approach to GCD Implementation
14
+const recursive_gcd = (a, b) => (b === 0) ? a : recursive_gcd(b, a%b);
15
16
+module.exports = {
17
+ gcd,
18
+ recursive_gcd
19
Number Theory/GCD/es6/test.js
@@ -0,0 +1,8 @@
+const { gcd, recursive_gcd } = require('./gcd');
+/************ Testing GCD ***************/
+console.log(gcd(5, 10));
+console.log(gcd(14, 35));
+console.log(recursive_gcd(5, 13));
+console.log(recursive_gcd(24, 60));
0 commit comments