GuobaGuoba Utils

intersection

@guoba-ai/utils / array / intersection

Function: intersection()

function intersection<T>(
   a, 
   b, 
   fn?): T[];

Defined in: array.ts:451

Return items in the first array that also exist in the second array. Source order and duplicate values from the first array are preserved.

Parameters

a

T[]

The source array

b

T[]

The array of items to match

fn?

(item) => unknown

Optional function to map items before comparison

Returns

T[]

A new array of items from a that also exist in b

Example

intersection([1, 2, 3, 4], [2, 4, 6]) // [2, 4]

On this page