DEV Community

Discussion on: How to remove duplicates element from array

Collapse
 
yaireo profile image
Yair Even Or
Collapse
 
ghamadi profile image
Ghaleb • Edited

Not even close.

For starters, it does not solve the proposed problem (filtering out duplicates); it returns the list of nonunique items.

Second, the time complexity of that solution is O(n2)O(n^2) . For an array of size nn , the filter function needs to run (ni)(n - i) iterations for each element at index ii .

Even if the goal is to return the list of nonunique items - which, again, is not the case here - a solution with O(n2)O(n^2) time complexity is most definitely not the "best".