Skip to content

Function.partition

github-actions[bot] edited this page Sep 5, 2026 · 27 revisions

umt / partition

Function: partition()

partition<T>(array, predicate): [T[], T[]]

Defined in: Array/partition.ts:9

Splits an array into two arrays based on a predicate

Type Parameters

T

T

Parameters

array

T[]

The array to partition

predicate

(value, index, array) => boolean

Function returning true for elements that go into the first array

Returns

[T[], T[]]

A tuple of [pass, fail] arrays

Example

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

API

Classes

Interfaces

Type Aliases

Variables

Functions

Clone this wiki locally