std/collections/mod.ts

Deno standard library
Go to Latest
function distinct
import { distinct } from "https://deno.land/std@0.147.0/collections/mod.ts?s=distinct";

Returns all distinct elements in the given array, preserving order by first occurrence

Example:

import { distinct } from "https://deno.land/std@0.147.0/collections/distinct.ts";
import { assertEquals } from "https://deno.land/std@0.147.0/testing/asserts.ts";

const numbers = [ 3, 2, 5, 2, 5 ]
const distinctNumbers = distinct(numbers)

assertEquals(distinctNumbers, [ 3, 2, 5 ])

Parameters

array: readonly T[][src]