Skip to content

Commit 3fd2c6d

Browse files
committed
Even and odd numbers sum from an array
1 parent 45c1343 commit 3fd2c6d

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

Diff for: EvenOddSums.js

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/* Even and odd numbers sum from an array */
2+
3+
/* Input an array as an argument to evenOddSums function and
4+
display sum or even and odd numbers */
5+
6+
function evenOddSums(arr) {
7+
let evenSum = 0;
8+
let oddSum = 0;
9+
arr.forEach(num => (num % 2 === 0 ? (evenSum += num) : (oddSum += num)));
10+
return [evenSum, oddSum];
11+
}
12+
13+
console.log(evenOddSums([20, 30, 11, 23, 40])) // [90, 34]

Diff for: README.md

+2
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,5 @@ Once Node.js is installed, individual scripts can be executed by running:
1919
* For example, "Listen" = "Silent", "evil" = "vile", "restful" = "fluster"
2020
* Generate all combinations of a string
2121
* Generate all combinations of an array
22+
* Add all numbers entered as function parameters
23+
* Even and odd numbers sum from an array

0 commit comments

Comments
 (0)