Sum of Odd Numbers (Set 7)

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

Example 1

sumOddNumbers()
Input
nums = [-19, -14, -26, 1, -40, -22, -19, 18, -11, -13, 36, -34, -16, 8, 17, 3, -30, -9, 34, 26, 5, 10, 44, 5, 31, -28, -34, -18, -4, -34, 20, 55, -35, -5, 19, 27, 34, 47, -23, -14, 34, 52, 5, -12, 27]
Output
108

Why

`sumOddNumbers` returns `108` for this input.

Example 2

sumOddNumbers()
Input
nums = [15, 42, 46, 44, 37, -23, 14, -39, 7, 9, 10, 29, -37, 17, -24, 14, 18, 23, 22, -28, 36, 20, -17, -35, 11, 46, -24]
Output
-3

Why

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