Nodejs Array Sum sum()

Here you can find the source of sum()

Method Source Code

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

// ANSWER ////from   w  w w .  j  a va2s .  c o m

var isVowel = function(chr) {
  return 'aeiou'.indexOf(chr) != -1;
}

function VowelCount(str) {
  return str.split('')
    .map(function(chr) {
      return isVowel(chr) ? 1 : 0;
    }).sum();
}

VowelCount(readline());

Related

  1. sum()
    Array.prototype.sum = function() {
      for (var sum = i = 0; i < this.length; i++) {
        sum += parseInt(this[i])
      };
      return sum
    
  2. sum()
    Array.prototype.sum = function(){
      "use strict";
      var count = 0;
      this.forEach(function(item){
        count += item;
      });
      return count;
    };
    
  3. sum()
    Array.prototype.sum = function(){
      'use strict';
      var count = 0;
      this.forEach(function(item){
        count += parseFloat(item) || 0;
      });
      return count;
    };
    
  4. 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());
    
  5. sum()
    function NavBarCtrl($scope) {
        $scope.isCollapsed = true;
    function randomnumber(limite) {
        return Math.ceil(Math.random() * limite);
    function getRandomInt(min, max) {
        return Math.floor(Math.random() * (max - min + 1)) + min;
    Array.prototype.sum = function() {
        var total = 0;
        for (var i = 0, _len = this.length; i < _len; i++) {
            total += this[i];
        return total;
    };
    
  6. sum()
    Array.prototype.sum = function() {
      var result = 0,
          i;
      for(i = 0; i < this.length; result += this[i++]); 
      return result;
     };
    
  7. sum()
    Array.prototype.sum = function () { 
      return this.reduce(function(a, b) { 
        return a + b; 
      }, 0); 
    
  8. 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());
    
  9. sum()
    Array.prototype.sum = function () {
      return this.reduce(function(a, b) {
        return a + b;
      });
    };
    console.log([1, 2, 3].sum());