Sum of Odd Numbers (Set 3)

Easy

Given an array of integers nums, return the sum of all its odd values, or 0 when every value is even.

Sum of Odd Numbers (Set 3) — the data. This set runs 4 cases: nums holds arrays of 17–23 items, with values from -40 to 54. The hidden cases are the largest of the set.

Example 1

sumOddNumbers()
Input
nums = [0, -35, 43, -16, 13, 12, -21, 15, 20, -4, 32, -28, 21, 7, 8, 16, 41, -25]
Output
59

Why

`sumOddNumbers` returns `59` for this input.

Example 2

sumOddNumbers()
Input
nums = [-26, 23, -2, 29, -27, 54, -5, 14, -40, -25, 7, -28, 42, 35, 29, 26, 25, 26, 19, -1, 31, 35, 24]
Output
175

Why

`sumOddNumbers` returns `175` 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 sumOddNumbers in the editor and return the answer — printing it is never graded.