es-toolkit 1.17.0-dev.545 → 1.17.0-dev.547
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/array/countBy.d.mts
CHANGED
|
@@ -14,6 +14,16 @@
|
|
|
14
14
|
* @param {(item: T) => K} mapper - The transformation function that maps each item to a key.
|
|
15
15
|
* @returns {Record<K, number>} An object containing the transformed items as keys and the
|
|
16
16
|
* counts as values.
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* const array = ['a', 'b', 'c', 'a', 'b', 'a'];
|
|
20
|
+
* const result = countBy(array, x => x);
|
|
21
|
+
* // result will be { a: 3, b: 2, c: 1 }
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* const array = [1, 2, 3, 4, 5];
|
|
25
|
+
* const result = countBy(array, item => item % 2 === 0 ? 'even' : 'odd');
|
|
26
|
+
* // result will be { odd: 3, even: 2 }
|
|
17
27
|
*/
|
|
18
28
|
declare function countBy<T, K extends PropertyKey>(arr: readonly T[], mapper: (item: T) => K): Record<K, number>;
|
|
19
29
|
|
package/dist/array/countBy.d.ts
CHANGED
|
@@ -14,6 +14,16 @@
|
|
|
14
14
|
* @param {(item: T) => K} mapper - The transformation function that maps each item to a key.
|
|
15
15
|
* @returns {Record<K, number>} An object containing the transformed items as keys and the
|
|
16
16
|
* counts as values.
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* const array = ['a', 'b', 'c', 'a', 'b', 'a'];
|
|
20
|
+
* const result = countBy(array, x => x);
|
|
21
|
+
* // result will be { a: 3, b: 2, c: 1 }
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* const array = [1, 2, 3, 4, 5];
|
|
25
|
+
* const result = countBy(array, item => item % 2 === 0 ? 'even' : 'odd');
|
|
26
|
+
* // result will be { odd: 3, even: 2 }
|
|
17
27
|
*/
|
|
18
28
|
declare function countBy<T, K extends PropertyKey>(arr: readonly T[], mapper: (item: T) => K): Record<K, number>;
|
|
19
29
|
|