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.
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.
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.