union

import { union } from "jsr:@ende/collections";

function

function union<T>(...arrays: Iterable<T>[]): T[]

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

...arrays: Iterable<T>[]

The arrays to get the union of.

Returns

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

Example: Basic usage

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

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

const shoppingList = union(soupIngredients, saladIngredients);

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

Source