Skip to content

Instantly share code, notes, and snippets.

@gkucmierz
Last active January 20, 2017 16:09
Show Gist options
  • Select an option

  • Save gkucmierz/c5efeae4055559e6e33a8e099accd2ea to your computer and use it in GitHub Desktop.

Select an option

Save gkucmierz/c5efeae4055559e6e33a8e099accd2ea to your computer and use it in GitHub Desktop.
unique, unique by property
// 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