From 84de2b6ab9e140114712899223c35821445eaee8 Mon Sep 17 00:00:00 2001 From: koushitha-30734 <2400030734@kluniversity.in> Date: Tue, 25 Nov 2025 08:56:47 +0530 Subject: [PATCH] Create JS-Code1 Thank you for contributing the JavaScript implementation for LCM of an array. It improves the project by adding a useful math utility method. Merging this PR now. Great work! --- JS-Code1 | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 JS-Code1 diff --git a/JS-Code1 b/JS-Code1 new file mode 100644 index 000000000..477243369 --- /dev/null +++ b/JS-Code1 @@ -0,0 +1,26 @@ + +function gcd(a, b) { + while (b !== 0) { + let temp = b; + b = a % b; + a = temp; + } + return a; +} + +function lcm(a, b) { + return (a * b) / gcd(a, b); +} + +// Function to find LCM of an array +function lcmOfArray(arr) { + let result = arr[0]; + for (let i = 1; i < arr.length; i++) { + result = lcm(result, arr[i]); + } + return result; +} + + +const arr = [4, 6, 8, 12]; +console.log("LCM:", lcmOfArray(arr));