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)
. For an array of size
n
, the filter function needs to run
(n−i)
iterations for each element at index
i
.
Even if the goal is to return the list of nonunique items - which, again, is not the case here - a solution with
O(n2)
time complexity is most definitely not the "best".
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Best answer:
stackoverflow.com/a/1838755/104380
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) . For an array of size n , the
filter
function needs to run (n−i) iterations for each element at index i .Even if the goal is to return the list of nonunique items - which, again, is not the case here - a solution with O(n2) time complexity is most definitely not the "best".