Created
August 17, 2016 08:27
-
-
Save ayozebarrera/63120897b69eb16fb99002f59acb2ad3 to your computer and use it in GitHub Desktop.
ES6 function that removes duplicated objects with the specified prop
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
/** | |
* 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; | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
<3