I like this one and I think it's a bit faster. Uses Sets as well.
and is obviously a lot more useful in real life since you'll be using objects and keys more than just numbers.
The snippet considers item to be have a key named id which is to be considered while making the uniqueArray sourceArray is basically the original array with duplicates.
I like this one and I think it's a bit faster. Uses Sets as well.
and is obviously a lot more useful in real life since you'll be using objects and keys more than just numbers.
online snippet
The snippet considers
itemto be have a key namedidwhich is to be considered while making theuniqueArraysourceArrayis basically the original array with duplicates.and can be written in one line if you'd like it that way.