• Group items into buckets keyed by their subtype, optionally sorting within each bucket. Items whose getSubType yields an empty/undefined value fall into the "other" bucket. Insertion order is preserved within a bucket unless compare is supplied.

    Type Parameters

    • T

    Parameters

    • items: readonly T[]

      The items to group.

    • getSubType: (item: T) => undefined | string

      Derives an item's subtype key.

    • Optionalcompare: (a: T, b: T) => number

      Optional within-bucket sort comparator.

    Returns Record<string, T[]>

    A map of subtype key → items in that bucket.