filter out duplicates from an array in TypeScript
code:
where {T} should be < T >
usage:
code:
export function isUnique{T}(value: T, index: number, self: T[]): boolean {
return self.indexOf(value) === index;
}
where {T} should be < T >
usage:
const uniqueItems = items.filter(isUnique);
Comments
Post a Comment