🤝 Returns an array of unique values that are present in all of the provided collections.
Info
It uses isEql for deep comparison of values.
Venn Diagram
Syntax
TypeScript
import { intersection } from '@opentf/std'; intersection( collections: unknown[][] = [], by?: (val: unknown) => unknown ): unknown[]
Parameters
collections: An array of arrays to find the intersection of.by: An optional iteratee invoked for each element to generate the criterion by which intersection is computed.
Returns
A new array containing the unique intersecting values.
Examples
TypeScript
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]