Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

sum of positive javascript

function positiveSum(arr) {
  return arr.reduce((acc, curr) => acc + (curr > 0 ? curr : 0))
}

positiveSum([1,2,-3,4]) // 7
 
PREVIOUS NEXT
Tagged: #sum #positive #javascript
ADD COMMENT
Topic
Name
8+5 =