Array
uniq

💎 Creates a unique version of an array by removing duplicate values.

It uses isEql for deep comparison of values.

Syntax

import { uniq } from '@opentf/std';
 
uniq<T>(
  arr: T[] = [],
  by?: (val: T) => unknown
): T[]

Parameters

  • arr: The source array.
  • by: An optional iteratee invoked for each element to generate the criterion by which uniqueness is computed.

Returns

A new array containing only unique values.

Examples

const arr = [1, 2, 2, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 5];
uniq(arr) //=> [1, 2, 3, 4, 5]
 
const nums = [2.1, 1.2, 2.3];
uniq(nums, Math.floor) //=> [2.1, 1.2]

Related

Try