Created
January 11, 2019 09:34
-
-
Save ritwickdey/3c5aaf513b0f71b2440cec8b2a5a616e to your computer and use it in GitHub Desktop.
MakeUnique
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
function makeUnique<T>(arr: T[], idSelector: (e: T) => string | number) { | |
const obj = {}; | |
arr.forEach(e => { | |
obj[idSelector(e)] = e; | |
}); | |
return Object.keys(obj).map(key => obj[key]) as T[]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment