basant307/AI_Governance_Project
048
1/**2 * Counts the occurrences of items in a Set based on a transformation function.3 *4 * This function takes a Set and a function that generates a key from each value.5 * It returns a Map with the generated keys and their counts as values.6 * The count is incremented for each element for which the transformation produces the same key.7 *8 * @template T - The type of elements in the Set.9 * @template K - The type of keys produced by the transformation function.10 * @param {Set<T>} set - The Set to count occurrences from.11 * @param {(value: T, value2: T, set: Set<T>) => K} mapper - The function to produce a key for counting.12 * @returns {Map<K, number>} A Map containing the mapped keys and their counts.13 *14 * @example15 * const set = new Set([1, 2, 3, 4, 5]);16 * const result = countBy(set, (value) => value % 2 === 0 ? 'even' : 'odd');17 * // result will be Map(2) { 'odd' => 3, 'even' => 2 }18 *19 * @example20 * const set = new Set(['apple', 'banana', 'cherry']);21 * const result = countBy(set, (value) => value.length);22 * // result will be Map(2) { 5 => 1, 6 => 2 }23 */24declare function countBy<T, K>(set: Set<T>, mapper: (value: T, value2: T, set: Set<T>) => K): Map<K, number>;25 26export { countBy };27 