Partitions an array into matched and unmatched groups by predicate result.
Returns [matched, unmatched] as a two-element tuple. Preserves original item order within each group. The predicate receives (item, index, array).
[matched, unmatched]
(item, index, array)
Array to split into two groups.
Called as (item, index, array); items for which this returns true go into the first group.
true
A two-element tuple [matched, unmatched], preserving original order within each group.
const [evens, odds] = partition([1, 2, 3, 4], (n) => n % 2 === 0);evens; // [2, 4]odds; // [1, 3]partition(["a", "bb", "ccc"], (s) => s.length > 1);// [["bb", "ccc"], ["a"]] Copy
const [evens, odds] = partition([1, 2, 3, 4], (n) => n % 2 === 0);evens; // [2, 4]odds; // [1, 3]partition(["a", "bb", "ccc"], (s) => s.length > 1);// [["bb", "ccc"], ["a"]]
Partitions an array into matched and unmatched groups by predicate result.
Returns
[matched, unmatched]as a two-element tuple. Preserves original item order within each group. The predicate receives(item, index, array).