split
split<
T>(predicate,arr): [T[],T[]]
Defined in: array/split.ts:20
Splits an array into two resulting arrays based on a predicate function.
Type Parameters
T
T
Parameters
predicate
(item) => boolean
The predicate function to determine the split
arr
T[]
The array to split
Returns
[T[], T[]]
A tuple containing two arrays: the first with elements that satisfy the predicate, and the second with elements that do not
Example
const isEven = (n: number) => n % 2 === 0;const [evens, odds] = split(isEven, [1, 2, 3, 4, 5, 6]);console.log(evens); // [2, 4, 6]console.log(odds); // [1, 3, 5]