Skip to content

Instantly share code, notes, and snippets.

@lukasbach
Created December 6, 2018 13:35
Show Gist options
  • Save lukasbach/d68185144119ef310b43a068eb9b70e8 to your computer and use it in GitHub Desktop.
Save lukasbach/d68185144119ef310b43a068eb9b70e8 to your computer and use it in GitHub Desktop.
const removeDuplicates<T> = (arr: T[], equal: (a: T, b: T) => boolean) =>
arr.filter((item, pos) => arr.indexOf(arr.find(inner => equal(inner, item)) === pos));
@lukasbach
Copy link
Author

Example usage: arr = removeDuplicates(array, (element1, element2) => element1.id === element2.id);

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