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.
any source?
Yes.
The higher-level methods (especially those for iteration) are indeed slower than their low-level counterparts. However,
Array#reduce
is still a native method that is optimized at the C-level. The difference in speed in most practical scenarios is negligible, the difference in elegance is not.Writing "good" code is about readability and expressiveness just as much as it is performance (not to say that this solution is the most of either). JavaScript gives us the syntactic sugar to make this possible. To ignore this in favor of more primitive concepts is a waste.
Which would you rather read?
vs.
If you start arguing about the relative speed of every single statement, you're going to waste a lot of time prematurely optimizing the readability out of your code.
You could also try the filter method or recursion to solve this :)
It's also good to expand on your knowledge and practice all methods of solving as well, regex being one of them even if they are slower :)