DEV Community

Discussion on: Remove duplicates from an Array the short & sweet way!

Collapse
 
leonardosnt profile image
Leonardo Santos

I don't think the Array.filter + Array.indexOf approach is more performant. Unless I'm missing something.

Both are linear, so for every item you are filtering, you are also iterating over the array again to find an index. Therefore, in the worst case, it will end up having a quadratic O(n^2) performance, which is really bad.