Function intersect
- intersect<T>(...arrays): T[]
Type Parameters
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.
Example: Basic usage
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"]);
Returns all distinct elements that appear at least once in each of the given arrays.