Quick actions

cmd+k|ctrl+k

Navigation

Languages

sum of postive

Snippet info

Language

JavaScript

Visibility

public

Author

misbahul.munir0224

Created

2024-09-24T16:14:21.594376Z

Updated

2024-09-24T16:14:21.594376Z

/* 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. */
//codewars 8kyu

function myFunc(a) {
    return a.filter(a => a > 0).reduce((a, b) => a+b, 0);
}
console.log(myFunc([3, 7, -7]));
INFO