Sunday, June 28, 2020

TypeScript hasDuplicates Function

Here is a simple TypeScript function that can be used to determine if a strongly typed TypeScript array contains duplicate items:

function hasDuplicates<T>(inputArray: T[]): boolean {
    return inputArray.length !== (new Set(inputArray)).size;
}

Example usage: