GuobaGuoba Utils

intersects

@guoba-ai/utils / array / intersects

Function: intersects()

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

Defined in: array.ts:327

Check if two arrays share any common elements.

Type Parameters

T

T

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

On this page