@jossmac/lil-libs
    Preparing search index...

    Function partition

    • 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).

      • T
      • arr: T[]

        Array to split into two groups.

      • predicate: (item: T, index: number, array: T[]) => boolean

        Called as (item, index, array); items for which this returns true go into the first group.

      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"]]