From f7431a3d8a9f41fbf0296346feeb8b34874c724f Mon Sep 17 00:00:00 2001 From: kalvium Date: Sat, 31 May 2025 10:31:29 +0530 Subject: [PATCH] function added --- Maths/lcm.cjs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 Maths/lcm.cjs 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 pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy