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.
This comment is hidden because it contains spoiler information about the solution
Harsh but true!
You should write one-liners only if you know what you're doing (like with programming in general
;)
).As you said, your solution is not optimal because of 2 passes over the input, and your code may crash with big enough inputs, though readability remains high in your case. If you look at my solution which avoids both your issues, you'll see that readability in my case is considerably lower, and the solution itself may be hard to understand.
Absolutely, don't be too obsessed with one-liners.