CoolFace
Datasetpublic

basant307/AI_Governance_Project

sourceHugging Faceapache-2.0updated 2mo agoView on Hugging Face
0likes45downloads
sumBy.js34 linesDownload Raw Back to lodash
1var baseIteratee = require('./_baseIteratee'),2    baseSum = require('./_baseSum');3 4/**5 * This method is like `_.sum` except that it accepts `iteratee` which is6 * invoked for each element in `array` to generate the value to be summed.7 * The iteratee is invoked with one argument: (value).8 *9 * @static10 * @memberOf _11 * @since 4.0.012 * @category Math13 * @param {Array} array The array to iterate over.14 * @param {Function} [iteratee=_.identity] The iteratee invoked per element.15 * @returns {number} Returns the sum.16 * @example17 *18 * var objects = [{ 'n': 4 }, { 'n': 2 }, { 'n': 8 }, { 'n': 6 }];19 *20 * _.sumBy(objects, function(o) { return o.n; });21 * // => 2022 *23 * // The `_.property` iteratee shorthand.24 * _.sumBy(objects, 'n');25 * // => 2026 */27function sumBy(array, iteratee) {28  return (array && array.length)29    ? baseSum(array, baseIteratee(iteratee, 2))30    : 0;31}32 33module.exports = sumBy;34 
basant307/AI_Governance_Project · CoolFace