Content-Length: 487 | pFad | http://github.com/TheAlgorithms/JavaScript/pull/1777.diff

thub.com diff --git a/Maths/lcm.cjs b/Maths/lcm.cjs new file mode 100644 index 0000000000..22c0eb1e7e --- /dev/null +++ b/Maths/lcm.cjs @@ -0,0 +1,17 @@ +function gcd(a, b) { + while (b !== 0) { + ;[a, b] = [b, a % b] + } + return a +} + +function lcm(a, b) { + if (a === 0 || b === 0) return 0 + return Math.abs(a * b) / gcd(a, b) +} + +module.exports = lcm + +console.log(lcm(12, 18)) // Output: 36 +console.log(lcm(5, 0)) // Output: 0 +console.log(lcm(7, 3)) // Output: 21








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/pull/1777.diff

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy