0.2.1 • Published 6 years ago
has-duplicate v0.2.1
has-duplicate
Returns true if an array has duplicate elements.
Based on find-indices-of-duplicates.
Install
npm install has-duplicate --saveAPI
has-duplicate
Parameters
arrayArray The array to checkcomparatorFunction The compare function (optional, defaultlodash.isequal)
Examples
import hasDuplicates from 'has-duplicate';
hasDuplicates([1, 2, 3]); // false
hasDuplicates([1, 2, 3, 1]); // true
hasDuplicates([{ v: 1 }, { v: 1 }]); // true
hasDuplicates([{ v: 1 }, { v: 2 }]); // false
hasDuplicates([{ v: 1 }, { v: 1 }], (a, b) => a === b); // falseReturns boolean True if has duplicates and false otherwise