Sum of Odd Numbers (Set 2)

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

Example 1

sumOddNumbers()
Input
nums = [-4, -30, -17, -22, -2, 37, -25, -3, -5, 5, -19]
Output
-27

Why

`sumOddNumbers` returns `-27` for this input.

Example 2

sumOddNumbers()
Input
nums = [37, -9, -36, -20, 41, 44, -20, -35, 21, 54, 40, -18, -22]
Output
55

Why

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