Array
intersection

Returns a unique array of values only containing elements from each of the collections.

It uses isEql for deep comparison of values.

Venn Diagram

Related

Syntax

import { intersection } from '@opentf/std';
 
intersection(
  collections: unknown[][] = [],
  by?: (val: unknown) => unknown
)

Examples

const setA = [1, 2];
const setB = [2, 3];
intersection([setA, setB]) //=> [2]
 
const arrays = [
  [1, 2, 3],
  [2, 1, 5],
  [3, 1],
];
intersection([...arrays]) //=> [1]
 
intersection(
  [
    [2.1, 1.2],
    [2.3, 3.4],
  ],
  Math.floor
) //=> [2.1]

Try