Ad
  • Custom User Avatar

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

  • Custom User Avatar

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

  • Custom User Avatar

    i complicated it for no reason :D

  • Custom User Avatar

    Please use spoiler flag also in solution comments as your comment is visible on the main page.

  • Custom User Avatar

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

  • Custom User Avatar

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

  • Custom User Avatar

    I became your fan for that

  • Custom User Avatar

    +1 @PomPolock, I wrote the lambda until I realized I had to list() the filter object. Then re-wrote as a list comprehension. Surprised that the testing structure doesn't let you check for the method used (see https://www.codewars.com/kata/59441520102eaa25260000bf).

  • Custom User Avatar

    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.

  • Custom User Avatar

    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 ?

  • Custom User Avatar

    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.

  • Custom User Avatar

    There are ~40 completions in Python, they run in about 2000-4000 ms.

  • Custom User Avatar

    Because Raul decided that was the last step, and didn't want you to do something else like filter all non-primes, remove all perfect squares, etc. . Once you figure out what has to be done, it is very simple coding.

  • Custom User Avatar

    This doesn't help the fact that I want to understand the task before trying it. This is not a puzzle, so the instructions should be clear enough not to make me look at the actual tests in attempt to figure out what the author wants me to do.

  • Custom User Avatar

    Hint: Take a look at the expected output of the sample tests. There is a consistent part of the answer that will help you know when you have the output it expects.

  • Loading more items...