Function union

  • Returns all distinct elements that appear in any of the given arrays.

    Type Parameters

    • T

      The type of the array elements.

    Parameters

    • Rest...arrays: Iterable<T, any, any>[]

      The arrays to get the union of.

    Returns T[]

    A new array containing all distinct elements from the given arrays.

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

    const soupIngredients = ["Pepper", "Carrots", "Leek"];
    const saladIngredients = ["Carrots", "Radicchio", "Pepper"];

    const shoppingList = union(soupIngredients, saladIngredients);

    assertEquals(shoppingList, ["Pepper", "Carrots", "Leek", "Radicchio"]);