mirror of
https://github.com/toss/es-toolkit.git
synced 2024-12-01 02:33:54 +03:00
docs(countBy): add missing example in jsdoc (#493)
* fix(countBy): add missing example * Update src/array/countBy.ts --------- Co-authored-by: Sojin Park <raon0211@gmail.com>
This commit is contained in:
parent
26b48d161b
commit
bd999b59f4
@ -14,6 +14,16 @@
|
||||
* @param {(item: T) => K} mapper - The transformation function that maps each item to a key.
|
||||
* @returns {Record<K, number>} An object containing the transformed items as keys and the
|
||||
* counts as values.
|
||||
*
|
||||
* @example
|
||||
* const array = ['a', 'b', 'c', 'a', 'b', 'a'];
|
||||
* const result = countBy(array, x => x);
|
||||
* // result will be { a: 3, b: 2, c: 1 }
|
||||
*
|
||||
* @example
|
||||
* const array = [1, 2, 3, 4, 5];
|
||||
* const result = countBy(array, item => item % 2 === 0 ? 'even' : 'odd');
|
||||
* // result will be { odd: 3, even: 2 }
|
||||
*/
|
||||
export function countBy<T, K extends PropertyKey>(arr: readonly T[], mapper: (item: T) => K): Record<K, number> {
|
||||
const result = {} as Record<K, number>;
|
||||
|
Loading…
Reference in New Issue
Block a user