Options
All
  • Public
  • Public/Protected
  • All
Menu

Module object/groupBy

Index

References

Functions

References

Renames and re-exports groupBy

Functions

  • groupBy<Fn>(fn: Fn): <Input>(obj: Input) => Input extends AnyArr ? Record<ReturnType<Fn>, Input> : Record<ReturnType<Fn>, ObjValues<Input>[]>
  • groupBy<Input, Fn>(fn: Fn, obj: Input): Input extends AnyArr ? Record<ReturnType<Fn>, Input> : Record<ReturnType<Fn>, ObjValues<Input>[]>
  • Creates an object composed of keys generated from the results of running each element of object thru fn. The corresponding value of each key is an array of elements responsible for generating the key.

    example
     groupBy(x => x, { a: 1, b: 1, c: 3});//=> { '1': [1, 1], '3': [3] }
    

    Type parameters

    • Fn: ((value: any, key: number, obj: any[]) => any) | ((value: any, key: number, obj: readonly any[]) => any) | ((value: any, key: any, obj: AnyObj) => any)

    Parameters

    • fn: Fn

      The function to transform value to group key. Receives three argument, value, key, obj.

    Returns <Input>(obj: Input) => Input extends AnyArr ? Record<ReturnType<Fn>, Input> : Record<ReturnType<Fn>, ObjValues<Input>[]>

    Returns the composed aggregate object.

      • <Input>(obj: Input): Input extends AnyArr ? Record<ReturnType<Fn>, Input> : Record<ReturnType<Fn>, ObjValues<Input>[]>
      • Type parameters

        Parameters

        • obj: Input

        Returns Input extends AnyArr ? Record<ReturnType<Fn>, Input> : Record<ReturnType<Fn>, ObjValues<Input>[]>

  • Creates an object composed of keys generated from the results of running each element of object thru fn. The corresponding value of each key is an array of elements responsible for generating the key.

    example
     groupBy(x => x, { a: 1, b: 1, c: 3});//=> { '1': [1, 1], '3': [3] }
    

    Type parameters

    • Input: AnyObjOrArr

    • Fn: ((value: any, key: number, obj: any[]) => any) | ((value: any, key: number, obj: readonly any[]) => any) | ((value: any, key: any, obj: AnyObj) => any)

    Parameters

    • fn: Fn

      The function to transform value to group key. Receives three argument, value, key, obj.

    • obj: Input

      The obj to iterate over.

    Returns Input extends AnyArr ? Record<ReturnType<Fn>, Input> : Record<ReturnType<Fn>, ObjValues<Input>[]>

    Returns the composed aggregate object.

Generated using TypeDoc