Or just use a Set and array.from ?
The "tricky" part is related to object duplicates. I'm not sure this approach would work with an array populated with non-primitive values
We're a place where coders share, stay up-to-date and grow their careers.
We strive for transparency and don't collect excess data.