has-duplicate
v0.2.1
Published
Returns true if an array has duplicate elements
Downloads
32
Readme
has-duplicate
Returns true if an array has duplicate elements.
Based on find-indices-of-duplicates.
Install
npm install has-duplicate --save
API
has-duplicate
Parameters
array
Array The array to checkcomparator
Function 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); // false
Returns boolean True if has duplicates and false otherwise