Sum of Even Numbers (Set 5)

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

Example 1

sumEvenNumbers()
Input
nums = [42, 20, 28, 3, 18, 28, -19, 31, -22, 27, 60, 36, -9, 34, 19, 34, 4, 43]
Output
282

Why

`sumEvenNumbers` returns `282` for this input.

Example 2

sumEvenNumbers()
Input
nums = [49, 24, 15, 27, -6, -14, -6, -20, 18, 9, -3, -14, -13, 14, 22, 25, 27, 11, 22, 46, -23, 6, -30, 14, -3, 28, 20]
Output
124

Why

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