CoolFace
Datasetpublic

basant307/AI_Governance_Project

sourceHugging Faceapache-2.0updated 2mo agoView on Hugging Face
0likes48downloads
reduce.d.ts29 linesDownload Raw Back to set
1/**2 * Reduces a Set to a single value by iterating through its elements and applying a callback function.3 *4 * This function iterates through all elements of the Set and applies the callback function to each element,5 * accumulating the result. If an initial value is provided, it is used as the starting accumulator value.6 * If no initial value is provided and the Set is empty, a TypeError is thrown.7 *8 * @template T - The type of elements in the Set.9 * @template A - The type of the accumulator.10 * @param {Set<T>} set - The Set to reduce.11 * @param {(accumulator: A, value: T, value2: T, set: Set<T>) => A} callback - A function that processes each element and updates the accumulator.12 * @param {A} [initialValue] - The initial value for the accumulator. If not provided, the first element in the Set is used.13 * @returns {A} The final accumulated value.14 * @throws {TypeError} If the Set is empty and no initial value is provided.15 *16 * @example17 * const set = new Set([1, 2, 3]);18 * const result = reduce(set, (acc, value) => acc + value, 0);19 * // result will be: 620 *21 * @example22 * const set = new Set([10, 20]);23 * const result = reduce(set, (acc, value) => acc + value);24 * // result will be: 30 (starts with first value 10)25 */26declare function reduce<T, A = T>(set: Set<T>, callback: (accumulator: A, value: T, value2: T, set: Set<T>) => A, initialValue?: A): A;27 28export { reduce };29 
basant307/AI_Governance_Project · CoolFace