Created
May 18, 2018 20:05
-
-
Save mohammad-haji/ed84fe16989542813db8e8785051a5f4 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
/** | |
* remove duplicates from array object with specific key | |
* @param arr | |
* @param key | |
* @return {Array.<T>|*} | |
*/ | |
export function removeDuplicates(arr, key) { | |
return arr.filter((obj, index, arr) => { | |
return arr.map(mapObj => { | |
return mapObj[key] | |
}).indexOf(obj[key]) === index; | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment