Nodejs Array Sum sum()

Here you can find the source of sum()

Method Source Code

// Problem ///*  w  ww .  j  av a  2  s .  c o  m*/

/*
Using the JavaScript language, have the function NumberSearch(str) take the
str parameter, search for all the numbers in the string, add them together,
then return that final number. For example: if str is "88Hello 3World!" the
output should be 91. You will have to differentiate between single digit
numbers and multiple digit numbers like in the example above. So "55Hello"
and "5Hello 5" should return two different answers. Each string will contain
at least one letter or symbol.
*/

// Helpers //

Array.prototype.sum=function(){return this.reduce(function(s,n){return s+n})}

// Answer //

function NumberAddition(str) {
  return str.replace(/[^\d]/g, ' ').split(' ').map(Number).sum();
}

NumberAddition(readline());

Related

  1. sum()
    Array.prototype.sum = function () { 
      return this.reduce(function(a, b) { 
        return a + b; 
      }, 0); 
    
  2. sum()
    Array.prototype.sum = function () {
      var sum,
        i;
      sum = 0;
      for (var i = 0; i < this.length; i++) {
        sum += this[i];
      };
      return sum;
    console.log([1, 3, 12, 33, 2].sum());
    
  3. sum()
    Array.prototype.sum = function () {
      return this.reduce(function(a, b) {
        return a + b;
      });
    };
    console.log([1, 2, 3].sum());
    
  4. sum()
    Array.prototype.sum = function () {
      return this.reduce(function (value, current) {
        return value + current;
      }, 0);
    };
    
  5. sum()
    Array.prototype.sum = function () {
      return (!this.length) ? 0 : this.reduce((acc, value) => {
        return acc + value;
      });
    };
    
  6. 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++) {
    ...
    
  7. sum()
    Array.prototype.sum = function() {
      var n = 0;
      this.forEach(function(e) {
        n += e;
      });
      return n;
    };
    
  8. 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++]);
    ...
    
  9. sum()
    Array.prototype.sum = function(){
      return this.reduce(function(sum, item){
        return sum + item;
      }, 0)
    function isInt(n){
        return Number(n) === n && n % 1 === 0;
    function isFloat(n){
    ...