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 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.
Hello, I'm new here. I've done many of the most completed 8 kyu JavaScript Kata(s) (low hanging fruit). The top answer for all that I can remember was one line of code. I always thought it would be better to spread it out over a few lines using descriptive variable names for readability. Since everyone seemed to be doing it in one line, I started following suit to the best of my ability. This is the first kata I did in one line where none of the top answers on the page were done in one line. To be fair, I learned lots of new coding shortcuts (map, =>, split/join) where before I would have used large for loops (I love this site for that), however it's probably better not to try to get it in one line, but rather aim for readability and best practice (especially for someone starting out). Right?