find-indices-of-duplicates

0.3.1 • Public • Published

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

Readme

Keywords

none

Package Sidebar

Install

npm i find-indices-of-duplicates

Weekly Downloads

1

Version

0.3.1

License

ISC

Unpacked Size

9.89 kB

Total Files

9

Last publish

Collaborators

  • safer-bwd