Skip to content

Instantly share code, notes, and snippets.

@mikemcbride
Created September 18, 2019 19:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mikemcbride/063583d4b08f526fa3995c0260c61f65 to your computer and use it in GitHub Desktop.
Save mikemcbride/063583d4b08f526fa3995c0260c61f65 to your computer and use it in GitHub Desktop.
Like uniqBy from lodash without needing all of lodash
// unique array of objects by specific key
const uniqBy = function (arr, key) {
let seen = new Set()
return arr.filter(it => {
let val = it[key]
if (seen.has(val)) {
return false
} else {
seen.add(val)
return true
}
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment