Module

std/collections/mod.ts>intersect

Deno standard library
Go to Latest
function intersect
import { intersect } from "https://dotland.deno.dev/std@0.116.0/collections/mod.ts";

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

Example:

import { intersect } from "https://deno.land/std@0.116.0/collections/mod.ts";
import { assertEquals } from "https://deno.land/std@0.116.0/testing/asserts.ts";

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

assertEquals(commonInterests, [ 'Cooking', 'Music' ])

Parameters

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