Sum of positives
EasyArrays3 min
Write a function sumPositive(numbers) that adds up only the positive numbers of an array and returns the sum. If there is nothing to add, return 0.
Examples
sumPositive([1, -4, 7, 12])Returns 20
sumPositive([])Returns 0
sumPositive([-1, -2])Returns 0
Loading the editor...
- Input
sumPositive([ 1, -4, 7, 12 ])Expected20 - Input
sumPositive([])Expected0 - Input
sumPositive([ -1, -2 ])Expected0
Hidden tests run on Submit