Loading collection data...
Collections are a way for you to organize kata so that you can create your own training routines. Every collection you create is public and automatically sharable with other warriors. After you have added a few kata to a collection you and others can train on the kata contained within the collection.
Get started now by creating a new collection.
You could break this down into a few steps with some descriptively-named variables (i.e.
positiveNumbers
,sumOfPositiveNumbers
). In a real project, this would help other developers understand your code more easily at a glance.why do you use filtering? it looks like over code. just check it in reduce.
why?
wrong
Using an initial value is unnecessarry since it's zero.
This leads to an extra circle through the array which is not needed here.
If you omit the initial value you will therefore save one circle.
See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/reduce#how_reduce_works_without_an_initial_value
However it has the benefit of only resorting to reduce, a function that can do anything, to perform its textbook application, hence better conveying intent. Maintanability saves more money than micro-optimization.