Skip to main content
Deno 2 is finally here 🎉️
Learn more
Module

x/fathym_common/src/src.deps.ts>partition

The Fathym Reference Architecture provides the common foundation for applications built in Typescript.
Go to Latest
function partition
import { partition } from "https://deno.land/x/fathym_common@v0.0.155/src/src.deps.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.

Examples

Example 1

import { partition } from "https://deno.land/std@0.224.0/collections/partition.ts";
import { assertEquals } from "https://deno.land/std@0.224.0/assert/assert_equals.ts";

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

assertEquals(even, [6, 8]);
assertEquals(odd, [5, 7, 9]);

Parameters

array: Iterable<T>
predicate: (el: T) => boolean

Returns

[T[], T[]]

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.

Examples

Example 1

import { partition } from "https://deno.land/std@0.224.0/collections/partition.ts";
import { assertEquals } from "https://deno.land/std@0.224.0/assert/assert_equals.ts";

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

assertEquals(even, [6, 8]);
assertEquals(odd, [5, 7, 9]);

Type Parameters

T
U extends T

Parameters

array: Iterable<T>
predicate: (el: T) => el is U

Returns

[U[], Exclude<T, U>[]]