Sum all elements in an array - Node.js Array

Node.js examples for Array:Sum

Description

Sum all elements in an array

Demo Code

if (typeof Array.prototype.sum != 'function') {
  Array.prototype.sum = function() {
    var result = 0;
    $.each(this, function(index, num) {
      result += num;//w w w.  jav  a2  s  .  c o  m
    });
    return result;
  };
}

Related Tutorials