UNPKG

@newdash/newdash

Version:

javascript/typescript utility library

29 lines (28 loc) 1.06 kB
import { ArrayIteratee, RecordIteratee } from "./types"; /** * Creates an object composed of keys generated from the results of running * each element of `collection` thru `iteratee`. The corresponding value of * each key is the number of times the key was returned by `iteratee`. The * iteratee is invoked with one argument: (value). * * @since 5.7.0 * @category Collection * @param collection The collection to iterate over. * @param iteratee The iteratee to transform keys. * @returns Returns the composed aggregate object. * @example * * ```js * const users = [ * { 'user': 'barney', 'active': true }, * { 'user': 'betty', 'active': true }, * { 'user': 'fred', 'active': false } * ] * * countBy(users, value => value.active); * // => { 'true': 2, 'false': 1 } * ``` */ export declare function countBy<T>(collection: ArrayLike<T>, iteratee: ArrayIteratee<T>): Record<string, number>; export declare function countBy<T>(collection: Record<string, T>, iteratee: RecordIteratee<T>): Record<string, number>; export default countBy;