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:
Junseong Park 2024-09-08 23:17:35 +09:00 committed by GitHub
parent 26b48d161b
commit bd999b59f4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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>;