Content-Length: 275222 | pFad | http://github.com/TheAlgorithms/JavaScript/commit/f7431a3d8a9f41fbf0296346feeb8b34874c724f

9A function added · TheAlgorithms/JavaScript@f7431a3 · GitHub
Skip to content

Commit f7431a3

Browse files
author
kalvium
committed
function added
1 parent 1d252d7 commit f7431a3

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

Maths/lcm.cjs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
function gcd(a, b) {
2+
while (b !== 0) {
3+
;[a, b] = [b, a % b]
4+
}
5+
return a
6+
}
7+
8+
function lcm(a, b) {
9+
if (a === 0 || b === 0) return 0
10+
return Math.abs(a * b) / gcd(a, b)
11+
}
12+
13+
module.exports = lcm
14+
15+
console.log(lcm(12, 18)) // Output: 36
16+
console.log(lcm(5, 0)) // Output: 0
17+
console.log(lcm(7, 3)) // Output: 21

0 commit comments

Comments
 (0)








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/TheAlgorithms/JavaScript/commit/f7431a3d8a9f41fbf0296346feeb8b34874c724f

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy