UNPKG

2.31 kBSource Map (JSON)View Raw
1{"version":3,"sources":["iterable/average.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAwB5C;;;;;;;GAOG;AACH,MAAM,UAAU,OAAO,CAAC,MAAqB,EAAE,OAA0B;IACvE,MAAM,EAAE,CAAC,UAAU,CAAC,EAAE,QAAQ,GAAG,QAAQ,EAAE,CAAC,SAAS,CAAC,EAAE,OAAO,EAAE,GAAG,OAAO,IAAI,EAAE,CAAC;IAClF,IAAI,GAAG,GAAG,CAAC,CAAC;IACZ,IAAI,KAAK,GAAG,CAAC,CAAC;IACd,KAAK,MAAM,IAAI,IAAI,MAAM,EAAE;QACzB,GAAG,IAAI,QAAQ,CAAC,IAAI,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;QACpC,KAAK,EAAE,CAAC;KACT;IAED,IAAI,KAAK,KAAK,CAAC,EAAE;QACf,MAAM,IAAI,KAAK,CAAC,kBAAkB,CAAC,CAAC;KACrC;IAED,OAAO,GAAG,GAAG,KAAK,CAAC;AACrB,CAAC","file":"average.js","sourcesContent":["import { identity } from '../util/identity';\nimport { MathOptions } from './mathoptions';\n\n/**\n * Computes the average of the iterable sequence.\n *\n * @export\n * @param {Iterable<number>} source The source iterable sequence to compute the average.\n * @param {MathOptions<number>} [options] The options for calculating the average.\n * @returns {number} The computed average for the iterable sequence.\n */\nexport function average(source: Iterable<number>, options?: MathOptions<number>): number;\n\n/**\n * Computes the average of the iterable sequence.\n *\n * @export\n * @template T The type of elements in the source sequence.\n * @param {Iterable<T>} source The source iterable sequence to compute the average.\n * @param {MathOptions<T>} [options] The options for calculating the average.\n * @returns {number} The computed average for the iterable sequence.\n */\nexport function average<T>(source: Iterable<T>, options?: MathOptions<T>): number;\n\n/**\n * Computes the average of the iterable sequence.\n *\n * @export\n * @param {Iterable<any>} source The source iterable sequence to compute the average.\n * @param {MathOptions<any>} [options] The options for calculating the average.\n * @returns {number} The computed average for the iterable sequence.\n */\nexport function average(source: Iterable<any>, options?: MathOptions<any>): number {\n const { ['selector']: selector = identity, ['thisArg']: thisArg } = options || {};\n let sum = 0;\n let count = 0;\n for (const item of source) {\n sum += selector.call(thisArg, item);\n count++;\n }\n\n if (count === 0) {\n throw new Error('Empty collection');\n }\n\n return sum / count;\n}\n"]}
\No newline at end of file