npm stats
  • Search
  • About
  • Repo
  • Sponsor
  • more
    • Search
    • About
    • Repo
    • Sponsor

Made by Antonio Ramirez

find-duplicates

2.0.3

@gajus

npmHomeRepoSnykSocket
Downloads:1
$ npm install find-duplicates
DailyWeeklyMonthlyYearly

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