알고리즘 30 - Sum of positive

jabae·2021년 10월 25일
0

알고리즘

목록 보기
30/97

Q.

You get an array of numbers, return the sum of all of the positives ones.

Example [1,-4,7,12] => 1 + 7 + 12 = 20

Note: if there is nothing to sum, the sum is default to 0.

A)

function positiveSum(arr) {
  return arr.filter(el => el > 0).reduce((sum, cur) => sum + cur, 0)
}
profile
it's me!:)

0개의 댓글