Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

calculate sum in empty array javascript

function sum(numbers){
  var x = numbers.reduce(function(prev,curr){
    return curr + prev;
  },0);
  return x;
}

alert(sum([1,2,3]));
alert(sum([]));
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #calculate #sum #empty #array #javascript
ADD COMMENT
Topic
Name
9+9 =