Skip to content

Instantly share code, notes, and snippets.

@ritwickdey
Created January 11, 2019 09:34
Show Gist options
  • Save ritwickdey/3c5aaf513b0f71b2440cec8b2a5a616e to your computer and use it in GitHub Desktop.
Save ritwickdey/3c5aaf513b0f71b2440cec8b2a5a616e to your computer and use it in GitHub Desktop.
MakeUnique
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