calculate sum in empty array javascript

Solutions on MaxInterview for calculate sum in empty array javascript by the best coders in the world

showing results for - "calculate sum in empty array javascript"
Rosalie
06 Mar 2018
1function sum(numbers){
2  var x = numbers.reduce(function(prev,curr){
3    return curr + prev;
4  },0);
5  return x;
6}
7
8alert(sum([1,2,3]));
9alert(sum([]));
similar questions
queries leading to this page
calculate sum in empty array javascript