Ad
  • Custom User Avatar

    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.

  • Custom User Avatar

    Absolutely, don't be too obsessed with one-liners.

  • Custom User Avatar

    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?