From ac6567a2de9c2ba2bf5e744189db8b733a685b23 Mon Sep 17 00:00:00 2001 From: Mahesh-rathod13 Date: Mon, 12 May 2025 16:56:05 +0530 Subject: [PATCH 1/2] feat : add function of sum of the array --- ArraySum.js | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 ArraySum.js diff --git a/ArraySum.js b/ArraySum.js new file mode 100644 index 0000000..43ae9fb --- /dev/null +++ b/ArraySum.js @@ -0,0 +1,9 @@ +const ArraySum = (numbers) =>{ + return numbers.reduce((accumulator, currentValue)=>{ + return accumulator + currentValue; + }, 0); +} + +export { + ArraySum +} \ No newline at end of file From 7a18804a0660737479f8f4d2094be2c9be12f5e4 Mon Sep 17 00:00:00 2001 From: Mahesh-rathod13 Date: Mon, 12 May 2025 17:15:29 +0530 Subject: [PATCH 2/2] fix : implement without using reduce funtion --- ArraySum.js | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/ArraySum.js b/ArraySum.js index 43ae9fb..8e247a0 100644 --- a/ArraySum.js +++ b/ArraySum.js @@ -1,7 +1,14 @@ const ArraySum = (numbers) =>{ - return numbers.reduce((accumulator, currentValue)=>{ - return accumulator + currentValue; - }, 0); + try { + let sum = 0; + for(let i=0;i