Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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.
- Host: GitHub
- URL: https://github.com/gajus/find-duplicates
- Owner: gajus
- License: other
- Created: 2018-06-29T10:47:41.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2020-02-05T06:31:22.000Z (almost 5 years ago)
- Last Synced: 2024-10-05T13:48:26.081Z (about 1 month ago)
- Topics: javascript, utility
- Language: JavaScript
- Size: 13.7 KB
- Stars: 8
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
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```