dedupe
TypeScript icon, indicating that this package has built-in type declarations

4.0.3 • Public • Published

dedupe

removes duplicates from your array.

Installation

npm install dedupe

Usage

primitive types

import dedupe from 'dedupe'

const a = [1, 2, 2, 3]
const b = dedupe(a)
console.log(b)

//result: [1, 2, 3]

complex types

Here the string representation of the object is used for comparism. Internal JSON.stringify is used for serialization. That means that {} is considered equal to {}.

import dedupe from 'dedupe'

const aa = [{a: 2}, {a: 1}, {a: 1}, {a: 1}]
const bb = dedupe(aa)
console.log(bb)

//result: [{a: 2}, {a: 1}]

complex types types with custom hasher

You can use a custom hasher to overwrite the default behaviour.

import dedupe from 'dedupe'

const aaa = [{a: 2, b: 1}, {a: 1, b: 2}, {a: 1, b: 3}, {a: 1, b: 4}]
const bbb = dedupe(aaa, value => value.a)
console.log(bbb)

//result: [{a: 2, b: 1}, {a: 1,b: 2}]

/dedupe/

    Package Sidebar

    Install

    npm i dedupe

    Weekly Downloads

    9,849

    Version

    4.0.3

    License

    MIT

    Unpacked Size

    3.83 kB

    Total Files

    7

    Last publish

    Collaborators

    • zaphod1984