super-utils-plus
Version:
A superior alternative to Lodash with improved performance, TypeScript support, and developer experience
20 lines (19 loc) • 744 B
TypeScript
/**
* Creates an object composed of keys generated from the results of running each element
* of collection through iteratee. The corresponding value of each key is an array of
* elements responsible for generating the key.
*
* @param array - The collection to iterate over
* @param iteratee - The function invoked per iteration or property name to group by
* @returns The composed aggregate object
*
* @example
* ```ts
* groupBy([6.1, 4.2, 6.3], Math.floor);
* // => { '4': [4.2], '6': [6.1, 6.3] }
*
* groupBy(['one', 'two', 'three'], 'length');
* // => { '3': ['one', 'two'], '5': ['three'] }
* ```
*/
export declare function groupBy<T>(array: T[], iteratee: ((value: T) => string | number) | keyof T): Record<string, T[]>;