@aegenet/belt-array-duplicates
v2.3.0
Published
Strip duplicates from array / get duplicates of an array.
Downloads
92
Readme
@aegenet/belt-array-duplicates
Strip duplicates from array / get duplicates of an array.
💾 Installation
yarn add @aegenet/belt-array-duplicates@^2.0.0
# or
npm i @aegenet/belt-array-duplicates@^2.0.0
📝 Usage
getDuplicates
import { getDuplicates } from '@aegenet/belt-array-duplicates';
const results = getDuplicates([1, 1, 2]);
// results = [1]
const results = getDuplicates([1, 1, 2, 3, 4, 4]);
// results = [1, 4]
stripDuplicates
import { stripDuplicates } from '@aegenet/belt-array-duplicates';
const results = stripDuplicates([{ id: 1 }, { id: 1 }, { id: 2 }], {
compare: (a, b) => a.id === b.id,
sorted: true,
}),
// results = [{ id: 1 }, { id: 2 }]
const a = { id: 1 };
const b = { id: 2 };
const results = stripDuplicates([a, a, b]),
// results = [{ id: 1 }, { id: 2 }]