common-stuff
    Preparing search index...

    Function indexBy

    • Creates indexed object by provided callback.

      If array is returned, creates a separate index for each array element.

      Type Parameters

      • T

      Parameters

      • array: T[]
      • keyCallback: (value: T) => string | number | readonly (string | number)[]

      Returns Record<string, T[]>

      indexBy(['one', 'two', 'three'], v => v.length)
      // { '5': ['three'], '3': ['one', 'two'] }

      indexBy(['one', 'two', 'three'], v => [v.length, v.length + 1])
      // { '5': ['three'], '6': ['three'], '3': ['one', 'two'], '4': ['one', 'two'] }
    • Creates indexed object by provided callback.

      If array is returned, creates a separate index for each array element.

      Type Parameters

      • T

      Parameters

      • array: readonly T[]
      • keyCallback: (value: T) => string | number | readonly (string | number)[]

      Returns Record<string, readonly T[]>

      indexBy(['one', 'two', 'three'], v => v.length)
      // { '5': ['three'], '3': ['one', 'two'] }

      indexBy(['one', 'two', 'three'], v => [v.length, v.length + 1])
      // { '5': ['three'], '6': ['three'], '3': ['one', 'two'], '4': ['one', 'two'] }