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.
I like this clever solution the most. However, I don't think it is best practice for producion. You will end up looping the string thrice. I know kata here does not considere the performance for evaluation but, for production, in JavaScript, it is not a good idea. After, seeing this, I will use the reduce method and save a loop. But still, it is not my preferred method when performance matters. But, I need to start thinking more on this kind of solution using map, filter, and reduce methods. It's amazing.
This solution only takes between 6 and 10 micro seconds to be executed against more than 45 microseconds of the here first rated solution. Indeed, an insignificant difference when you process one string.