알고리즘 66 - Sum of positive

tamagoyakii·2021년 10월 20일
0

알고리즘

목록 보기
66/89

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((acc, cur) => acc + cur, 0)
}

0개의 댓글