UNPKG

@newdash/newdash

Version:

javascript/typescript utility library

31 lines (30 loc) 1.47 kB
import { ArrayIteratee, Collection, KeyIteratee, RecordIteratee } from "./types"; /** * Creates an object composed of keys generated from the results of running * each element of `collection` thru `iteratee`. The order of grouped values * is determined by the order they occur in `collection`. The corresponding * value of each key is an array of elements responsible for generating the * key. The iteratee is invoked with one argument: (value). * * @since 5.5.0 * @category Collection * @param collection The collection to iterate over. * @param identity The iteratee to transform keys. * @returns Returns the composed aggregate object. * @example * * ```js * groupBy([6.1, 4.2, 6.3], Math.floor); * // => { '4': [4.2], '6': [6.1, 6.3] } * * // The `property` iteratee shorthand. * groupBy(['one', 'two', 'three'], 'length'); * // => { '3': ['one', 'two'], '5': ['three'] } * ``` */ export declare function groupBy<T>(result: Collection<T>): Record<string, Array<T>>; export declare function groupBy<T>(result: ArrayLike<T>, iteratee: KeyIteratee): Record<string, Array<T>>; export declare function groupBy<T>(result: Record<string, T>, iteratee: KeyIteratee): Record<string, Array<T>>; export declare function groupBy<T>(result: ArrayLike<T>, iteratee: ArrayIteratee<T, any>): Record<string, Array<T>>; export declare function groupBy<T>(result: Record<string, T>, iteratee: RecordIteratee<T, any>): Record<string, Array<T>>; export default groupBy;