Skip to content

Instantly share code, notes, and snippets.

@ayozebarrera
Created August 17, 2016 08:27
Show Gist options
  • Save ayozebarrera/63120897b69eb16fb99002f59acb2ad3 to your computer and use it in GitHub Desktop.
Save ayozebarrera/63120897b69eb16fb99002f59acb2ad3 to your computer and use it in GitHub Desktop.
ES6 function that removes duplicated objects with the specified prop
/**
* removes duplicated objects with the specified prop
* @param {Array} myArr [our collection to check]
* @param {String} prop [name of the property to compare]
* @return {Array} [unique array]
*/
removeDuplicates = (myArr, prop) => {
return myArr.filter((obj, pos, arr) => {
return arr.map(mapObj => mapObj[prop]).indexOf(obj[prop]) === pos;
});
}
@ayozebarrera
Copy link
Author

<3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment