find-indices-of-duplicates
v0.3.1
Published
Returns indexes of duplicate elements in an array
Downloads
42
Readme
find-indices-of-duplicates
Returns indexes of duplicate elements in an array.
Install
npm install find-indices-of-duplicates --save
API
find-indices-of-duplicates
Parameters
array
Array The array to searchcomparator
Function The compare function (optional, defaultlodash.isequal
)options
Object (optional, default{}
)
Examples
import findIndexesOfDuplicates from 'find-indices-of-duplicates';
const users = [
{ id: 1, name: 'Jon' },
{ id: 2, name: 'Fred' },
{ id: 3, name: 'Bob' },
{ id: 2, name: 'Jon' },
{ id: 4, name: 'Mike' },
{ id: 2, name: 'Fred' },
{ id: 1, name: 'Jon' },
];
findIndexesOfDuplicates(users); // [[0, 6], [1, 5]]
const comparator = (user1, user2) => user1.id === user2.id
findIndexesOfDuplicates(users, comparator); // [[0, 6], [1, 3, 5]]