Skip to main content
Module

std/collections/mod.ts>partition

Deno standard library
Go to Latest
function partition
import { partition } from "https://deno.land/std@0.102.0/collections/mod.ts";

Returns a tuple of two arrays with the first one containing all elements in the given array that match the given predicate and the second one containing all that do not

Example:

const numbers = [ 5, 6, 7, 8, 9 ]
const [ even, odd ] = partition(numbers, it => it % 2 == 0)

console.assert(even === [ 6, 8 ])
console.assert(odd === [ 5, 7, 9 ])

Parameters

array: Array<T>
predicate: Predicate<T>

Returns

[Array<T>, Array<T>]