Nodejs Array Sum sum(fun)

Here you can find the source of sum(fun)

Method Source Code

Array.prototype.sum = function (fun) {
    var result = 0;
    this.forEach(x => result += fun ? fun(x) : x);
    return result;
};

Related

  1. sum()
    Array.prototype.sum = function(){
      return this.reduce((acc,x) => acc + x);
    
  2. sum()
    Array.prototype.sum = function() {
      return this.isEmpty() ? 0 : this.reduce( (a, b) => { return a + b} );
    };
    
  3. sum()
    Array.prototype.sum = function() {
      for ( var a = 0, c = this.length, b = 0; a < c; b += this[a++]) {
      return b
    };
    
  4. sum(array)
    Array.prototype.sum = function(array) { 
        return this.reduce(function(a,b) { 
            return a + b 
        }) 
    
  5. sum(begin, end)
    Array.prototype.sum = function(begin, end) {
      var total = 0;
      for (var i = begin >> 0 || 0, len = end + 1 >> 0 || this.length >> 0; i < len; i++) {
        total += +this[i] || 0;
      return total;
    };
    
  6. sum(func)
    Array.prototype.sum = function (func) {
        var length = this.length,
            sum = 0;
        for (var i = 0; i < length; i++) {
            sum += func(this[i]);
        return sum;
    function isUndefinedNullOrEmpty(item) {
    ...
    
  7. sum(prop)
    Array.prototype.sum = function (prop) {
        var total = 0;
        for ( var i = 0, _len = this.length; i < _len; i++ ) {
            total += this[i][prop]
        return total;
    };
    
  8. sum(s)
    Array.prototype.sum = function (s) {
      s = s || Selector;
      var l = this.length;
      var sum = 0;
      while (l-- > 0) sum += s(this[l]);
      return sum;
    };
    
  9. sum(selector)
    Array.prototype.sum = function(selector) {
        if (typeof selector !== 'function') {
            selector = function(item) {
                return item;
        var sum = 0;
        for (var i = 0; i < this.length; i++) {
            sum += selector(this[i]);
    ...