GuobaGuoba Utils

intersects

@guoba-ai/utils / array / intersects

Function: intersects()

function intersects<T>(
   a, 
   b, 
   fn?): boolean;

Defined in: array.ts:433

Check if two arrays share any common elements.

Parameters

a

T[]

The first array

b

T[]

The second array

fn?

(item) => unknown

Optional function to map items before comparison

Returns

boolean

true if the arrays have at least one common element

Example

intersects([1, 2], [2, 3]) // true

intersects([1, 2], [3, 4]) // false

intersects([{ id: 1 }, { id: 2 }], [{ id: 2 }], item => item.id) // true

Warning

Without fn, object values are compared by reference, not by shape.

On this page