Ad
  • Default User Avatar

    I agree with @cbalci and @igandecki. A single loop that iterates the array once is faster than looping the array multiple times.

  • Custom User Avatar

    I agree. This is not a best practice. The instance should be protected from direct modification by declaring it as a variable inside a closure.

  • Custom User Avatar

    Comparing 'for loop' to 'indexOf' is not the correct analysis here. The above solution goes throught the remaining list every time it removes an item. @Igandecki's point is fair. A single pass solution can be more efficent than this one.

  • Custom User Avatar

    Very interesting, I have no idea how this could possibly be true.. I will have to investigate. :)

    Thanks!