Arrays.distinct()

Syntax

function distinct<T>(iterable: Iterable<T>): T[]

Returns a new array of only the unique values of the iterable (without duplicates).

Parameters
iterable

The iterable you want without duplicates.

Example

import { Arrays } from 'potence';

const array = ['a', 'a', 'b', 'b', 'c', 'e', 'e', 'e'];

Arrays.distinct(array);  // -> ['a', 'b', 'c', 'e']

Remarks

This function compares values for value types and references for reference types.

This function uses Set internally to remove the duplicate values, so prefer to use Set directly if you are able to do so.

This function does not modify the original iterable but returns a new array instead.

Compare Arrays.hasDuplicates().