Sum of Odd Numbers (Set 10)

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 10) — the data. This set runs 4 cases: nums holds arrays of 42–47 items, with values from -40 to 55. The hidden cases are the largest of the set.

Example 1

sumOddNumbers()
Input
nums = [23, -21, 13, 54, 8, 22, -8, -24, -22, -39, 34, -38, 37, -40, -25, 2, 41, -40, 39, 1, 9, 3, -16, 24, -1, -14, -27, 54, 37, -26, 54, 5, 12, -9, -17, 31, 47, 14, 9, 26, 36, 11, 0, 10, 44, 50]
Output
167

Why

`sumOddNumbers` returns `167` for this input.

Example 2

sumOddNumbers()
Input
nums = [-4, 30, 11, -11, -9, 0, -20, -3, 47, 18, -3, -25, 38, -37, -33, 33, 0, 14, 11, -1, -13, 47, 44, -40, 7, 8, 48, 43, -1, 48, -32, 18, 35, 35, -32, 31, 12, 26, -12, -34, 18, -15, -37, -14, -20, 8, -14]
Output
112

Why

`sumOddNumbers` returns `112` 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.