Skip to content

Commit 10afe89

Browse files
committed
LCM code added
1 parent e0e7e3b commit 10afe89

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

Number Theory/LCM/lcm.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/* Least Commond Multiple (LCM) Finding in JavaScript */
2+
3+
function lcm(a, b) {
4+
return (a / gcd(a,b)) * b;
5+
}
6+
7+
function gcd(a, b) {
8+
while (true) {
9+
var remainder = a%b;
10+
if (remainder === 0) return b;
11+
12+
a = b;
13+
b = remainder;
14+
}
15+
}
16+
17+
18+
/************ Testing LCM ***************/
19+
console.log(lcm(5, 10));
20+
console.log(lcm(14, 35));

0 commit comments

Comments
 (0)