0.0.2 • Published 5 years ago

@pelevesque/find-indexes-of-duplicates v0.0.2

Weekly downloads
3
License
MIT
Repository
github
Last release
5 years ago

Build Status Coverage Status JavaScript Style Guide

find-indexes-of-duplicates

Finds indexes of duplicates in an array of elements.

find-indexes-of-duplicates uses lodash.isequal to make comparisons, so any type supported by lodash.isequal is supported by find-indexes-of-duplicates.

Node Repository

https://www.npmjs.com/package/@pelevesque/find-indexes-of-duplicates

Installation

npm install @pelevesque/find-indexes-of-duplicates

Tests

Standard Style & Unit Tests

npm test

Unit Tests & Coverage

npm run cover

Usage

Requiring

const findIndexesOfDuplicates = require('@pelevesque/find-indexes-of-duplicates')

One Set of Duplicates

const elements = [
  'd131dd02c5e6eec4', // a
  '55ad340609f4b302',
  'd131dd02c5e6eec4', // a
  'd131dd02c5e6eec4', // a
  'd8823e3156348f5b'
]
const result = findIndexesOfDuplicates(elements)
// result === [[0, 2, 3]]

Many Sets of Duplicates

const elements = [
  'd131dd02c5e6eec4', // a
  '55ad340609f4b302',
  'd8823e3156348f5b', // b
  'd131dd02c5e6eec4', // a
  'd8823e3156348f5b', // b
  '551111111114b302', // c
  '551111111114b302'  // c
]
const result = findIndexesOfDuplicates(elements)
// result === [[0, 3], [2, 4], [5, 6]]

Using the stopAtFirstSet Flag

// When using the stopAtFirstSet flag, only the first set is returned.
// Note: In this case, an array is returned instead of an array of arrays.
const elements = [
  'd131dd02c5e6eec4', // a
  '55ad340609f4b302',
  'd8823e3156348f5b', // b
  'd131dd02c5e6eec4', // a
  'd8823e3156348f5b', // b
  '551111111114b302', // c
  '551111111114b302'  // c
]
const stopAtFirstSet = true
const result = findIndexesOfDuplicates(elements, stopAtFirstSet)
// result === [0, 3]