Skip to content

Commit 7d6ad3c

Browse files
committed
Refactor sum function to filter non-numeric values and ensure correct summation
1 parent 0667c52 commit 7d6ad3c

1 file changed

Lines changed: 2 additions & 0 deletions

File tree

‎Sprint-1/implement/sum.js‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
function sum(elements) {
2+
const numbers = elements.filter((item) => typeof item === "number");
3+
return numbers.reduce((total, current) => total + current, 0);
24
}
35

46
module.exports = sum;

0 commit comments

Comments
 (0)