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?
tbh, I would rather read the second one. But of course I'm biased, comming from a C background.
this should be the best solution!
just a comment: best comments is the own code.
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.
This comment is hidden because it contains spoiler information about the solution
You could also try the filter method or recursion to solve this :)
yeah, i thought about regex before anything, than i tried the for loop.
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 :)
regex can be 87% slower than own implementation using for loop. shouldnt matter tho. gg
shouldn't reduce be slower than a regular for loop? http://jsperf.com/reduce-vs-loop/2
http://jsperf.com/reduce-vs-loop/2
Make it legible and understandable. Sure, it's a one liner. But not everyone will get it first try. So, my advice is: Just make it simpler.