Created
December 6, 2018 13:35
-
-
Save lukasbach/d68185144119ef310b43a068eb9b70e8 to your computer and use it in GitHub Desktop.
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
const removeDuplicates<T> = (arr: T[], equal: (a: T, b: T) => boolean) => | |
arr.filter((item, pos) => arr.indexOf(arr.find(inner => equal(inner, item)) === pos)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Example usage:
arr = removeDuplicates(array, (element1, element2) => element1.id === element2.id);