Skip to main content

Function: partition()

partition<T>(array: T[], predicate: (value: T, index: number) => boolean): T[][]

Partitions array into a tuple of two arrays, where one array contains all elements that satisfies predicate, and the other contains all elements that do not satisfy predicate.

Type parameters

Type parameter
T

Parameters

ParameterTypeDescription
arrayT[]The array to partition. This array is not mutated.
predicate(value: T, index: number) => booleanThe predicate function to determine in which partition the item should be placed. The function should return true for items that should be placed in the first partition, and false for those that should be placed in the second partition.

Returns

T[][]

A tuple of two arrays.

Source

lib/partition.ts:12