Earn extra honor and gain new allies!
Honor is earned for each new codewarrior who joins.
Learn more
  • 44193521?v=4

    Yeah just for the purpose of the kata since that is the direct equivalent JS's Array Filter function. It's good to understand the lambda syntax for usage with map and reduce, as well as other more involved filter functions (where it wouldn't be as appropriate to use the "x for x" expression). Objectively though, neither solution is better than the other if the only goal is to return an array with only even integers.

    It's kind of similar in a way to the dynamic programming problems with the fibonacci or factorial sequence where you utilize recursion. For the purpose of writing a function that generates those sequences, recursion isn't necessary but it makes for good practice to start developing an understanding of it.

    For many complex programming topics, it's usually easier to understand how they work in a simple problem that may not necessarily require their usage. But learning how they work on the simple problems will make the more complex problems that require them more easy to understand.

  • 13283801?v=4

    Ah, so you're trying to say thah it would have been better to use filter with a lambda function other than a conditional like this ?

  • 44193521?v=4

    While this solution effectively works the same and is definitely a correct answer to the problem, I would say that it somewhat defeats the purpose of the kata. Due to the nature of python, it is not reasonably possible to limit syntax usage in manner that you're able to in JS, especially for this problem. Perhaps I might have been able to have the function return the filter expression instead of the filtered array itself, but that might have been overkill for a white kata.

    This is not at all a wrong way of "filtering" any array using a conditional, but doesn't do anything to teach the usage of lambda expressions in python. In most practical environments you would probably use the "element for element in iterable" expressions, but it is useful to understand how lambda expressions work.

  • Profile pic

    I wanted to do the same with scipy.special.binom(n, k),
    but got a Max Buffer Size Reached.
    Did you know why I got this error?

  • Profile pic
  • 32236948?v=4

    because the tests are shit and do not assert correctly floating point values...

  • 29553056?v=4

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

  • 14838451?v=4

    I love oneliners, especially when they are so clear and easy to read! .endswith is what I was looking for. Domo arigato.

  • Profile pic

    I ran the code and it FAILED this test:

     Testing for [1, 1, 0, 1, 1]
    It should work for random inputs too: 'Yes' should equal 'No'
  • Profile pic
  • Profile pic

    when the key=[1,1,1] the test flase

    should join a determine

    if the list length is not n*n should "No"

  • 18006651?v=3

    How this code handles non perfect square keys? I got one in my attempt

  • 42092799?v=4
  • 36845719?v=4

    ale żes się nagimnastykował ale działa :)

  • 12795864?v=3

    You have a good point there, indeed.

    I would measure it against a simple if index is even .. else loop, but that's probably not any faster. Thanks for the heads up!

  • Loading more items...