r/javascript • • Mar 02 '19

Useful javascript one-liners.

https://medium.com/@smellycode/js-one-liners-8bc0a6af2345?source=friends_link&sk=a9295a05aef9e514e137fca7eeb89cd1
344 Upvotes

96 comments sorted by

View all comments

6

u/Drugba Mar 03 '19

I absolutely love [...new Set(arr)] for removing dupes from an array of primitives. That being said, if I was using it in a shared codebase, I'd be sure to add a comment explaining it as I don't think it's super clear at first glance.

1

u/sharlos Mar 03 '19

You could wrap it in a function spelling it out maybe?

2

u/Drugba Mar 03 '19

Totally could. Personal preference, I'm not a fan of single line functions, but yeah, you totally could make a removeDupes function.