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.
Stackoverflow post referenced states that switch-immediate (which this is) is actually the fastest.
Also it's eight years old now and js uses a totally different optimizing compiler in 2020.
While it depends on the environment and the specific case, the safest bet for performance nowadays is switch over if-else.
https://jsperf.com/if-switch-lookup-table/113
This comment is hidden because it contains spoiler information about the solution
In High Performance JavaScript, Nicholas Zakas talks about conditionals vs. if-else statements:
https://www.safaribooksonline.com/library/view/high-performance-javascript/9781449382308/ch04s02.html
Why not use .every()
You cannot within
.map()
, as areturn
statement just exit the relevant function, in this case the one inside the.map()
method.If that is your goal, you might wish to use something like an ordinary loop, iterating over the array.
It's a ES6 feature, enabled via Babel.
That's great to hear!
It can be found in your profile:
http://www.codewars.com/users/mark-outlast/comments
This comment is hidden because it contains spoiler information about the solution
Actually you should completely ignore the first argument of apply function - in this particular case scope does not matter so 0 seems a good option since it's easiest to type (easier than null).
The reason I use apply in the firt place is to create new array with every value set to "undefined". Unfortunately that's the only way to create new array of length n without any holes and without using loops. You can read more about this here: http://speakingjs.com/es5/ch18.html (section "Function.prototype.apply()").