Ad
  • Custom User Avatar

    Any difference with looping through smileys first then check membership in arr?

  • Custom User Avatar

    You are right, my solution is shorter. I solved it without lambda :D

  • Custom User Avatar

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

  • Custom User Avatar

    It avoids unnecessary computation in the event of an empty input.

  • Default User Avatar

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

  • Custom User Avatar

    No problem :)

  • Custom User Avatar

    Mutating an array in a function is usually a bad practise because it modifies it permanently and you cannot revert the process. Mutating an array is good as long as it is a method of a class, for example: python has .sort() which is a method of the list class.

    The Kata author has done:

    lst = [random.randint(-1000,1000) for _ in range(random.randint(0,1000))]
    Test.assert_equals(invert(lst), answer(lst))
    

    What happens is that your solution ("invert" function) will modify the original array, and this modified array will be the parameter for the user's solution ("answer" function); therefore changing out the real expected solution.

    I'm not sure if the Kata author did this accidently or purposely, but this "issue" is fine to be left because it stops people modifing the original array (deterring them to stop modifying the parameter). When making a Kata, I would usually do the same, however, I would inform the user not to mutate it in any way.

    It can be "fixed" by:

    lst = [random.randint(-1000,1000) for _ in range(random.randint(0,1000))]
    sol = answer(lst)
    Test.assert_equals(invert(lst), sol)
    
  • Custom User Avatar

    Don't modify the original array.