Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/gajus/find-duplicates

Finds duplicate entries in a JavaScript array using an iteratee.
https://github.com/gajus/find-duplicates

javascript utility

Last synced: 20 days ago
JSON representation

Finds duplicate entries in a JavaScript array using an iteratee.

Awesome Lists containing this project

README

        

# find-duplicates

[![Travis build status](http://img.shields.io/travis/gajus/find-duplicates/master.svg?style=flat-square)](https://travis-ci.org/gajus/find-duplicates)
[![Coveralls](https://img.shields.io/coveralls/gajus/find-duplicates.svg?style=flat-square)](https://coveralls.io/github/gajus/find-duplicates)
[![NPM version](http://img.shields.io/npm/v/find-duplicates.svg?style=flat-square)](https://www.npmjs.org/package/find-duplicates)
[![Canonical Code Style](https://img.shields.io/badge/code%20style-canonical-blue.svg?style=flat-square)](https://github.com/gajus/canonical)
[![Twitter Follow](https://img.shields.io/twitter/follow/kuizinas.svg?style=social&label=Follow)](https://twitter.com/kuizinas)

Finds duplicate entries in a JavaScript array using an iteratee.

## API

```js
type DuplicatePointerType = {|
+index: number,
+value: T,
|};

const findDuplicates = (members: $ReadOnlyArray, iteratee: (T) => string) => $ReadOnlyArray<$ReadOnlyArray>>;

```

## Usage

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

```js
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.

```bash
$ npm run benchmark

```