Sum of Odd Numbers (Set 4)

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

Example 1

sumOddNumbers()
Input
nums = [-5, 30, 1, -11, -39, 32, -8, -27, -5, 22, 15, 40, 1, -39, 45, 46]
Output
-64

Why

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

Example 2

sumOddNumbers()
Input
nums = [-3, -29, 11, -22, 46, 3, -23, -4, 55, 24, 23, -38, 51, -1, 46, 19, 15, 0, 37, -24, -33, 43, -28, -9, 18, 16, -32]
Output
159

Why

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