Sequence NODE_147
Easy

Sum of Array Elements

JavaScript
Technical Specification

Return the sum of all numbers in an array.

Input/Output Samples
Input:[1, 2, 3, 4]
Output:10
Input:[]
Output:0
Optimal Logic Path
function sumArray(arr) {
  return arr.reduce((sum, num) => sum + num, 0);
}
Architectural Deep-Dive
reduce lets us accumulate the array values into a single total.