common-stuff
    Preparing search index...

    Function groupBy

    • Groups an array's items into [key, values] entries, keyed by the callback's return value.

      Internally backed by a Map keyed on the raw callback value, so:

      • Object/array keys use identity (two equal-but-different object instances are distinct groups). For value equality, return a primitive key.
      • Functions, symbols, and circular references work (no JSON.stringify).
      • Entries are returned in first-seen order.

      Type Parameters

      • T
      • G

      Parameters

      • array: T[]
      • keyCallback: (value: T) => G

      Returns [G, T[]][]

      groupBy([6.1, 4.2, 6.3], Math.floor)
      // [ [6, [6.1, 6.3]], [4, [4.2]] ]
    • Groups an array's items into [key, values] entries, keyed by the callback's return value.

      Internally backed by a Map keyed on the raw callback value, so:

      • Object/array keys use identity (two equal-but-different object instances are distinct groups). For value equality, return a primitive key.
      • Functions, symbols, and circular references work (no JSON.stringify).
      • Entries are returned in first-seen order.

      Type Parameters

      • T
      • G

      Parameters

      • array: readonly T[]
      • keyCallback: (value: T) => G

      Returns readonly [G, readonly T[]][]

      groupBy([6.1, 4.2, 6.3], Math.floor)
      // [ [6, [6.1, 6.3]], [4, [4.2]] ]