Answers for "calculate sum in empty array javascript"

0

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([]));
Posted by: Guest on August-20-2021

Code answers related to "calculate sum in empty array javascript"

Code answers related to "Javascript"

Browse Popular Code Answers by Language