Function intersect

  • Returns all distinct elements that appear at least once in each of the given arrays.

    Type Parameters

    • T

      The type of the elements in the input arrays.

    Parameters

    • Rest...arrays: (readonly T[])[]

      The arrays to intersect.

    Returns T[]

    An array of distinct elements that appear at least once in each of the given arrays.

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

    const lisaInterests = ["Cooking", "Music", "Hiking"];
    const kimInterests = ["Music", "Tennis", "Cooking"];
    const commonInterests = intersect(lisaInterests, kimInterests);

    assertEquals(commonInterests, ["Cooking", "Music"]);