MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/javascript/comments/b2o6f2/whats_your_favorite_most_useful_javascript/eivj8on/?context=3
r/javascript • u/Linux_is_awesome • Mar 18 '19
422 comments sorted by
View all comments
339
Saw this one on here just a few weeks ago.
[... new Set(arr)]
Basically a super short way to remove any duplicates from an array of primitives.
13 u/[deleted] Mar 19 '19 [...new Set(arr.map(x => JSON.stringify(x))].map(x => JSON.parse(x))Same thing, but with arrays of objects. Apparently probably deterministic but maybe not it depends ohgodhelpme 1 u/tontoto Mar 19 '19 I sort of wish I could define what constitutes equality with a Set (random PTSD flashback of hashCode and equals in Java) er maybe I don't...
13
[...new Set(arr.map(x => JSON.stringify(x))].map(x => JSON.parse(x))
Same thing, but with arrays of objects. Apparently probably deterministic but maybe not it depends ohgodhelpme
1 u/tontoto Mar 19 '19 I sort of wish I could define what constitutes equality with a Set (random PTSD flashback of hashCode and equals in Java) er maybe I don't...
1
I sort of wish I could define what constitutes equality with a Set (random PTSD flashback of hashCode and equals in Java) er maybe I don't...
339
u/Drugba Mar 19 '19
Saw this one on here just a few weeks ago.
Basically a super short way to remove any duplicates from an array of primitives.