partition es-toolkit
Returns a tuple that splits an array into two groups based on a condition.
Usage
partition(arr, isInTruthy)
Use partition when you want to separate elements in an array into two groups based on a specific condition. It separates elements for which the condition function returns true and elements for which it returns false into different arrays.
It returns two empty arrays for an empty array.
Parameters
The array to split into two groups.
A condition function that determines whether each element should be included in the first array (truthy) or the second array (falsy). The function is called with the value, its index, and the entire array.
Returns
A tuple consisting of two arrays. The first array contains elements for which the condition is true, and the second array contains elements for which the condition is false.
Source: es-toolkit
Re-exported verbatim from es-toolkit. Implementation, edge cases, and performance behavior are owned upstream. This page mirrors the documentation at the pinned version; the linked source is authoritative.