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 16584df7d1110b7a76c0e7076368592000bd68c3 Mon Sep 17 00:00:00 2001 From: Mahesh-rathod13 Date: Mon, 12 May 2025 17:07:09 +0530 Subject: [PATCH 2/2] fix : Wrap in try catch block --- ArraySum.js | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/ArraySum.js b/ArraySum.js index 43ae9fb..6a99615 100644 --- a/ArraySum.js +++ b/ArraySum.js @@ -1,9 +1,11 @@ -const ArraySum = (numbers) =>{ - return numbers.reduce((accumulator, currentValue)=>{ - return accumulator + currentValue; +const ArraySum = (numbers) => { + try { + return numbers.reduce((accumulator, currentValue) => { + return accumulator + currentValue; }, 0); -} + } catch (error) { + console.log(error); + } +}; -export { - ArraySum -} \ No newline at end of file +export { ArraySum };