Content-Length: 787 | pFad | http://github.com/TheAlgorithms/JavaScript/pull/1777.patch
thub.com
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
--- a PPN by Garber Painting Akron. With Image Size Reduction included!Fetched URL: http://github.com/TheAlgorithms/JavaScript/pull/1777.patch
Alternative Proxies:
Alternative Proxy
pFad Proxy
pFad v3 Proxy
pFad v4 Proxy