Last active
July 2, 2020 15:31
-
-
Save hmtri1011/4d5c1881d1d90c9ba7af3428b1a3055e to your computer and use it in GitHub Desktop.
Unique by without lodash
This file contains 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
const uniqBy = (array, key) => { | |
const mapKey = array.reduce((prev, cur) => { | |
const keyValue = key ? cur[key] : cur | |
return { | |
...prev, | |
[keyValue]: cur | |
} | |
}, {}) | |
return Object.values(mapKey) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment