Nullifying Precipitation Machine
Wondering what’s next for npm?Check out our public roadmap! »

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
 

Install

npm i find-duplicates

DownloadsWeekly Downloads

25

Version

2.0.3

License

none

Unpacked Size

10.1 kB

Total Files

6

Last publish

Collaborators

  • avatar