Skip to content

Latest commit

 

History

History
40 lines (31 loc) · 784 Bytes

distinct.md

File metadata and controls

40 lines (31 loc) · 784 Bytes

distinct

Used to create a new collection with the distinct values. It compares each item using a deep compare algorithm witch compares all property values seperatly.

If you need to compare using a custom comparator, use distinctBy instead.

Syntax:
distinct()
Usage in a reducer:
array.reduce(distinct())

Arguments:
None

Usage:

const testData = [
    { p1: 10, p2: 'a' },
    { p1: 10, p2: 'a' },
    { p1: 20, p2: 'a' },
    { p1: 20, p2: 'b' }
]

const res = testData.reduce(distinct(), [])

// Result:
// [
//     { p1: 10, p2: 'a' },
//     { p1: 20, p2: 'a' },
//     { p1: 20, p2: 'b' }
// ]

Remarks:

See also: