Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

how to sum array elements in javascript

// codewars solution
// leetcode solution
// and more

function sum(arr) {
  return arr.reduce( (x,y) => x+y, 0);
}

sum([1, 2, 3, 4]);
// 10
sum([2, 4, 1, 3, 5]);
// 15

// enjoy :)
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #sum #array #elements #javascript
ADD COMMENT
Topic
Name
6+4 =