Loading collection data...
Collections are a way for you to organize kata so that you can create your own training routines. Every collection you create is public and automatically sharable with other warriors. After you have added a few kata to a collection you and others can train on the kata contained within the collection.
Get started now by creating a new collection.
I agree with @cbalci and @igandecki. A single loop that iterates the array once is faster than looping the array multiple times.
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.
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.
Very interesting, I have no idea how this could possibly be true.. I will have to investigate. :)
Thanks!
Since isn't really a closure, there is public access to change Singleton.__instance. Is this really best practice?
@Igandecki
Time complexity is bounded by indexOf and splice which is the fastest way since we dont have to iterate through the array completely. Strangly even doing indexOf multiple times is faster than interating through the array completely. So it's the best way to do it.
source: http://jsperf.com/js-for-loop-vs-array-indexof/8