0.3.1 • Published 4 years ago

find-indices-of-duplicates v0.3.1

Weekly downloads
2
License
ISC
Repository
github
Last release
4 years ago

find-indices-of-duplicates

Build Status

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 search
  • comparator Function The compare function (optional, default lodash.isequal)
  • options Object (optional, default {})
    • options.fromIndex number The index to search from (optional, default 0)
    • options.onlyFirstSet boolean The flag, if true only the first set is returned (optional, default false)
    • options.onlyFirst boolean The flag, if true only the first duplicate is returned (optional, default false)

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]]

Returns Array<Array> The array of found indexes sets