Ad
  • Custom User Avatar

    The current solution upvote system slightly rewards shorter code over efficient code on many problems. I think this might change in the future if they decide to show the average runtime of each solution.

    +5Kyu kata check for efficiency more often as a requirement to pass the tests. On lower level kata, you can mostly expect short solutions that are far from being considered best practices.

    Other reason for writing shorter code is simply having a little bit of fun. I've done it myself.

  • Custom User Avatar

    Hello Diego. I think It's an ingenious use of Map and Reduce but those methods are unnecesary in this case as they make you go twice through the array when you only need to traverse it once. The Map/Reduce also make the solution harder to read in this case, in part because of how you wrote the code.

    Best regards and feel free to ask me anything and I'll get to it if I can help you. You are on the right track in any case and mainly need to focus on making your code cleaner.

  • Custom User Avatar

    To summarize a lot, code that is "best practices":

    1. "Explains itself" (is easy and simple to understand for a collegue).
    2. Avoids Side-Effects.
    3. Has good or optimal performance in terms of Time Complexity (how the time that the function takes to execute increases related to the input size).
    4. Is easy to mantain.

    Sometimes, if the function is simple enough, you can accomplish all this with one line of code. Usually, however, you can't. Many one-line solutions have poor time complexity, since they often use array methods that make the complexity at least O(n^2). If they don't have poor time complexity, they are often hard to understand for a less experienced collegue.

    If your code is properly split into many simple and clear pure functions, many of them can be one liners and they will be easy to understand because they are doing just a single thing. But here you will usually see one-liners that are a long, inefficient chain of high order array methods.

    That being said, writing one line solutions can be extremely fun and I often do it. But they should never be voted as Best Practices.

    If you are interested in learning more about best practices and clean code, you can search the work of Robert C. Martin. That man has great books on programming and many talks on youtube, and he gives examples based on real-life work situations that you could encounter while coding in the future.

  • Custom User Avatar

    It's harder than most 7kyus. Katas that have been approved recently tend to be harder. Try sorting 7Kyu katas by a criteria other than "Newest" and see how difficult you find those.

  • Custom User Avatar

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

  • Custom User Avatar

    You are not returning the value (●'◡'●)

  • Custom User Avatar

    Hello! What you are logging on items there is strange, since "items" is the input that you must scan/parse to check how long is the longest consecutive sequence of "key" in it. It's likely that you slightly misunderstood the problem or that there's a mistake in your code. I and many others solved this with a very simple and straightforward solution and the kata worked just fine (it isn't broken).

  • Custom User Avatar

    Case 3 is amazing and opened my mind a bit more.

  • Custom User Avatar

    Wonderful solution, I'm glad I read this.

  • Custom User Avatar
  • Custom User Avatar

    What a God. This has better time complexity than the other solutions.

  • Custom User Avatar

    The test says that ten people are left out! Read the problem again.

    ༼ つ ◕_◕ ༽つ

  • Custom User Avatar

    You are well on your way to being a great programmer. You don't lack an innate capability or intelligence if you got this far!

  • Custom User Avatar

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

  • Custom User Avatar

    This Kata was surprisingly difficult for me and I enjoyed it very much. I learned something new by solving this and by reading the other solutions.

    Thanks (●'◡'●)

  • Loading more items...