Nodejs Array Sum sum()

Here you can find the source of sum()

Method Source Code

Array.prototype.sum = function(){
   return this.reduce(function(sum, item){
      return sum + item;
   }, 0)//from w  w  w  .j a v  a2  s .  co  m
}

function isInt(n){
    return Number(n) === n && n % 1 === 0;
}

function isFloat(n){
    return Number(n) === n && n % 1 !== 0;
}

Related

  1. sum()
    Array.prototype.sum = function () {
      return (!this.length) ? 0 : this.reduce((acc, value) => {
        return acc + value;
      });
    };
    
  2. sum()
    Array.prototype.sum=function(){return this.reduce(function(s,n){return s+n})}
    function NumberAddition(str) {
      return str.replace(/[^\d]/g, ' ').split(' ').map(Number).sum();
    NumberAddition(readline());
    
  3. sum()
    function extend(destination, source) {
        for (var property in source) {
            destination[property] = source[property];
        return destination;
    Array.prototype.sum = function() {
        var result = 0;
        for (var i = 0; i < this.length; i++) {
    ...
    
  4. sum()
    Array.prototype.sum = function() {
      var n = 0;
      this.forEach(function(e) {
        n += e;
      });
      return n;
    };
    
  5. sum()
    Math.TAU = Math.PI * 2;
    Array.prototype.sum = function()
      for (var i = 0, L = this.length, sum = 0; i < L; sum += this[i++]);
      return sum;
    Array.prototype.product = function()
      for (var i = 0, L = this.length, product = 1; i < L; product =  product * this[i++]);
    ...
    
  6. sum()
    Array.prototype.sum = function() {
      var sum = 0;
      this.forEach(function(k) {
        sum += k;
      });
      return sum;
    };
    
  7. sum()
    Array.prototype.sum = function()
      if (this.length < 1) {
        return Number.NaN;
      var sum = 0;
      this.forEach(function(a) {
        sum += a;
      });
    ...
    
  8. sum()
    Array.prototype.sum = function () {
        return this.reduce(function(previousValue, currentValue) {
            return previousValue + currentValue;
        });
    };
    
  9. sum()
    Array.range = function(start, count) {
      var newArray = [];
      for( var i = 0, j = start; i< count; i++, j++)
        newArray.push(j);
      return newArray;
    Array.prototype.sum = function () {
        var sum = 0;
        this.forEach(function (value) {
    ...