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're right about the O(n) complexity, but you're still adding the overhead of an extra function call for every character instead of one function call for the whole string.
I did a jsperf and it indicates performance is significantly improved just by moving
.toUpperCase()
out of themap
function and putting it before.split('')
so that it's outside of that loop... http://jsperf.com/touppercase-function-callSince the solution grouping algorithm groups without respect to semicolons, it's not really fair to say "this" isn't best practice because the semicolons are omitted; "this" includes several solutions with complete semicolon usage (including my own).
With regard to toUpperCase... yeah, I realized that afterward, though I'm not really sure about the savings. I bet under the covers calling toUpperCase on a string loops through the string one character at a time and swaps to the uppercase char, which is pretty much the same as what's happening above; the complexity certainly isn't higher--O(n)--either way.
It's minor but I think you'd get better performance calling toUpperCase once on the word rather than separately on every individual letter.
Also, omitting semicolon line terminators isn't best practice. It's acceptable when you're trying to minify/obfuscate your code; otherwise they should be included. (I don't know which variation you saw but the one I see has 4 missing semicolons.)
best practice