Sum of Odd Numbers (Set 9)

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

Example 1

sumOddNumbers()
Input
nums = [4, -21, -9, -12, 23, -36, 19, 28, -12, -11, 26, -20, -21, 20, -26, 10, 40, 28, 34, -25, -15, 25, -17, -23, -9, 13, 55, -4, -29, -23, 1, 24, 55, -36, 10, 11, -32, 25, 23]
Output
47

Why

`sumOddNumbers` returns `47` for this input.

Example 2

sumOddNumbers()
Input
nums = [-29, -22, -2, 45, 40, -38, 52, -5, -25, 54, -2, 49, 7, -39, -21, 49, 10, 42, -2, -20, -38, 25, 49, -19, -36, -35, -14, -4, -6, 27, 9, -11, -37, -38, -26, -24, -10, -24, -10, -23]
Output
16

Why

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