Ad
  • Default User Avatar

    This comment is hidden because it contains spoiler information about the solution

  • Custom User Avatar
  • Custom User Avatar

    OCD says capatalized should be spelled capitalized :)

  • Custom User Avatar

    Only one test in Java as well

  • 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?

  • Custom User Avatar

    I agree. I'm new here and I'm still working on all the low hanging fruit. Most of the top answers I've seen so far have been one liners (and very enlightening). I was shocked this solution wasn't at the top of the list. Even people who aren't programmers know there's a formula for summation (no offense). This was my first upvote for best practice.