function partition
partition<T>(
list: T[],
predicate: (item: T) => boolean
): [T[], T[]]

Splits a list into two: the first contains items where the predicate is true, the second contains items where it is false.

Examples

Example 1

partition([1, 2, 3, 4], (n) => n % 2 === 0); // [[2, 4], [1, 3]]

Type Parameters

Parameters

list: T[]
predicate: (item: T) => boolean

Return Type

[T[], T[]]

Usage

import { partition } from ".";