Skip to content

Commit 7ade271

Browse files
authored
Update gcd.js
1 parent 9f884aa commit 7ade271

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

gcd.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ const euclideanGCD = (a, b) => {
33
return a;
44
}
55
// swap if a is lesser than b
6-
if (b > a) {
6+
if (a < b) {
77
a = a ^ b;
88
b = a ^ b;
99
a = a ^ b;
@@ -16,6 +16,6 @@ const gcd = (a, b) => {
1616
if (b === 0) return a;
1717

1818
for (let i = Math.min(a, b) >> 1; i >= 1; i--) {
19-
if (a % i === 0 && b % i === 0) return i;
19+
if(!(a%i) && !(b%i)) return i;
2020
}
2121
};

0 commit comments

Comments
 (0)