get sum from a list

@param {Array} array - array
@param {Function} fn - iterator
433849
function sum(array, fn) {
  fn = fn || func.self;
  return array.reduce(function(memo, v) {
    return memo + fn(v);
  }, 0);
}
254520
function forEach(obj, fn) {
  // Don't bother if no value provided
  if (obj === null || typeof obj === 'undefined') {
    return;
  }

  // Force an array if not already something iterable
  if (typeof obj !== 'object') {
    /* eslint no-param-reassign:0 */
    obj = [obj];
  }

  if (Array.isArray(obj)) {
    // Iterate over array values
    for (let i = 0, l = obj.length; i < l; i += 1) {
      fn.call(null, obj[i], i, obj);
    }
  } else {
    // Iterate over object keys
    Object.entries(obj).forEach(([key, val]) => {
      fn.call(null, val, key, obj);
    });
  }
}
401869
function average(array) {
  var length = array.length;

  if (length === 0) {
    throw new RangeError("Error");
  }

  var index = -1;
  var result = 0;

  while (++index < length) {
    result += array[index];
  }

  return result / length;
}
456204
public static float Sum(float[] data) {
        float sum = 0;
        for (int i = 0; i < data.length; i++) {
            sum += data[i];
        }
        return sum;
    }
376783
function sum(x) {
        var value = 0;
        for (var i = 0; i < x.length; i++) {
            value += x[i];
        }
        return value;
    }
980550
function forAll(arr, fn) {
    var out = [], i;
    for (i = 0; i < arr.length; i++) {
        out.push(fn(arr[i], i));
    }

    return out;
}
117434
function reduce(array, callback) {
    var accumulator = null;
    each(array, function(value, index) {
      accumulator = callback(accumulator, value, index, array);
    });
    return accumulator;
  }
101899
function(array, fun) {
      return _.reduce(array, function(x, y) {
        return fun(x, y) ? x : y;
      });
    }
250983
function filter(array, f) {
        if (array) {
            var len = array.length;
            var i = 0;
            while (i < len && f(array[i]))
                i++;
            if (i < len) {
                var result = array.slice(0, i);
                i++;
                while (i < len) {
                    var item = array[i];
                    if (f(item)) {
                        result.push(item);
                    }
                    i++;
                }
                return result;
            }
        }
        return array;
    }
707336
function(fn) {
			var item = utils.find(this._list, function(item) {
				return item.fn === fn;
			});
			if (item) {
				this._list.splice(this._list.indexOf(item), 1);
			}
		}
1248883
public function Sum( $Func = null )
	{
		$items = $this->Select( $Func );
		$sum   = 0;

		foreach ( $items as $item ) $sum += $item;

		return $sum;
	}
313056
function forEach(f, arr) {
  if (NATIVE_ARRAY_FOREACH) {
    if (arr) {
      NATIVE_ARRAY_FOREACH.call(arr, f);
    }

    return;
  }

  for (var i = 0; i < arr.length; i++) {
    f(arr[i], i, arr);
  }
}
362975
function array_sum_interval($array_external, $interval){

        $n_interval=explode(":", $interval);
        $sum = 0;
        for($i=$n_interval[0]; $i < ($n_interval[1]+1) ; $i++){
            $sum += $array_external[$i];
        }
        return $sum;

    }
27605
function remove(array, fn) {
  const idx = array.findIndex(fn)
  if (idx !== -1) {
    array.splice(idx, 1)
  }
}
615873
static public function listSum($list, $field,$callback = null)
    {
        $sum = 0;
        foreach ($list as $row) {
            if ($callback instanceof \Closure) {
                if ($callback($row) === true) {
                    $sum += $row[$field];
                }
            }else {
                $sum += $row[$field];
            }
        }
        return $sum;
    }
38337
def sum(self, callback=None):
        
        if callback is None:
            return sum(self.items)

        callback = self._value_retriever(callback)

        return self.reduce(lambda result, item: (result or 0) + callback(item))
241088
function $sum(params) {
    if (Array.isArray(params) && params.every(p => typeof p === 'number')) {
        return params.reduce((t, n) => t + n, 0);
    }
    throw new Error('$sum expects an array of number');
}