Sum of Even Numbers (Set 12)

Easy

Given an array of integers nums, return the sum of all its even values. 0 counts as even, and an array with no even value scores 0.

Sum of Even Numbers (Set 12) — the data. This set runs 4 cases: nums holds arrays of 48–48 items, with values from -30 to 60. The hidden cases are the largest of the set.

Example 1

sumEvenNumbers()
Input
nums = [35, 52, 41, 21, 39, 11, -7, -17, 36, 41, 38, -29, 34, -5, -25, 29, 55, 54, -22, -4, -10, -19, -5, -30, 37, 52, 55, 52, -15, 59, 5, 51, -6, 25, 60, -27, 40, 28, -24, 24, -17, 2, 4, 41, 6, 59, 5, -23]
Output
386

Why

`sumEvenNumbers` returns `386` for this input.

Example 2

sumEvenNumbers()
Input
nums = [-23, -18, -5, -12, 57, 42, 52, -1, -29, -9, -23, -23, -8, -26, -25, 2, 5, -21, 14, 12, 10, 28, 0, -24, 8, -3, 45, -23, -14, 45, 25, 22, -22, -5, 23, 21, 34, -30, 13, 31, 13, 46, -27, 58, -16, 47, 47, 47]
Output
158

Why

`sumEvenNumbers` returns `158` for this input.
Constraints
2 <= nums.length <= 10^4
-10^3 <= nums[i] <= 10^3
Every case in this set must pass: the first two are visible on Run, the last two unlock on Submit.

Topics

ArraysMath

Implement sumEvenNumbers in the editor and return the answer — printing it is never graded.