Sum of Even Numbers (Set 4)

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 4) — the data. This set runs 4 cases: nums holds arrays of 21–29 items, with values from -30 to 59. The hidden cases are the largest of the set.

Example 1

sumEvenNumbers()
Input
nums = [-7, 16, -28, 3, -16, 14, 19, -28, 12, 25, 52, -5, 21, -18, -10, 31, 0, 42, -2, -16, 32, 25]
Output
50

Why

`sumEvenNumbers` returns `50` for this input.

Example 2

sumEvenNumbers()
Input
nums = [15, -10, 21, -6, -5, -7, 38, -15, 9, 43, 59, 12, 21, 56, 5, 37, 23, 26, -14, -15, 11]
Output
102

Why

`sumEvenNumbers` returns `102` 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.