Function distinct

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

    Uniqueness is determined by same-value-zero equality.

    Type Parameters

    • T

      The type of the elements in the input array.

    Parameters

    • array: Iterable<T, any, any>

      The array to filter for distinct elements.

    Returns T[]

    An array of distinct elements in the input array.

    import { distinct } from "@std/collections/distinct";
    import { assertEquals } from "@std/assert";

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

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