Last active
January 20, 2017 16:09
-
-
Save gkucmierz/c5efeae4055559e6e33a8e099accd2ea to your computer and use it in GitHub Desktop.
unique, unique by property
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // return array with unique elements | |
| function unique(arr) { | |
| return arr.filter((el, i) => arr.indexOf(el, i+1) === -1); | |
| } | |
| // return array with unique elements by property | |
| function uniqueByProp(arr, sel) { | |
| let filter = arr.map(sel).map((el, i, arr) => arr.indexOf(el, i+1) === -1); | |
| return arr.filter((n, i) => filter[i]); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment