Skip to content

Commit 6846c4a

Browse files
committed
Improved JavaScript implementation of Euclidean
1 parent c6ff7bb commit 6846c4a

File tree

1 file changed

+22
-23
lines changed

1 file changed

+22
-23
lines changed
Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,31 @@
1-
function euclid_mod(a, b){
2-
a = Math.abs(a);
3-
b = Math.abs(b);
1+
function euclidMod(a, b) {
2+
a = Math.abs(a);
3+
b = Math.abs(b);
44

5-
var temp;
6-
while (b != 0){
7-
temp = b;
8-
b = a%b;
9-
a = temp;
10-
}
5+
let temp;
6+
while (b !== 0) {
7+
temp = b;
8+
b = a % b;
9+
a = temp;
10+
}
1111

12-
return a;
12+
return a;
1313
}
1414

15-
function euclid_sub(a, b){
16-
a = Math.abs(a);
17-
b = Math.abs(b);
15+
function euclidSub(a, b) {
16+
a = Math.abs(a);
17+
b = Math.abs(b);
1818

19-
while (a != b){
20-
if (a > b){
21-
a = a - b;
22-
}
23-
else{
24-
b = b - a;
25-
}
19+
while (a !== b) {
20+
if (a > b) {
21+
a -= a - b;
22+
} else {
23+
b = b - a;
2624
}
25+
}
2726

28-
return a;
27+
return a;
2928
}
3029

31-
console.log(euclid_mod(64*67, 64*81));
32-
console.log(euclid_sub(128*12, 128*77));
30+
console.log(euclidMod(64 * 67, 64 * 81));
31+
console.log(euclidSub(128 * 12, 128 * 77));

0 commit comments

Comments
 (0)