find-duplicates

2.0.3 • Public • Published

find-duplicates

Travis build status Coveralls NPM version Canonical Code Style Twitter Follow

Finds duplicate entries in a JavaScript array using an iteratee.

API

type DuplicatePointerType<T> = {|
  +index: number,
  +value: T,
|};
 
const findDuplicates = <T: *>(members: $ReadOnlyArray<T>, iteratee: (T) => string) => $ReadOnlyArray<$ReadOnlyArray<DuplicatePointerType<T>>>;
 

Usage

findDuplicates produces an array of duplicate input array entries as identified using iteratee function.

import findDuplicates from 'find-duplicates';
 
const haystack = [
  {
    id: 1,
    name: 'a'
  },
  {
    id: 2,
    name: 'b'
  },
  {
    id: 3,
    name: 'a'
  },
  {
    id: 4,
    name: 'b'
  },
  {
    id: 5,
    name: 'c'
  }
];
 
const duplicates = findDuplicates(haystack, (subject) => {
  return subject.name;
});
 
duplicates;
[
  [
    {
      index: 0,
      value: {
        id: 1,
        name: 'a'
      }
    },
    {
      index: 2,
      value: {
        id: 3,
        name: 'a'
      }
    }
  ],
  [
    {
      index: 1,
      value: {
        id: 2,
        name: 'b'
      },
    },
    {
      index: 3,
      value: {
        id: 4,
        name: 'b'
      },
    },
  ]
]
 

Benchmark

Run benchmark before making changes and ensure that performance does not degrade after changes.

$ npm run benchmark
 

Dependents (3)

Package Sidebar

Install

npm i find-duplicates

Weekly Downloads

11

Version

2.0.3

License

none

Unpacked Size

10.1 kB

Total Files

6

Last publish

Collaborators

  • gajus