Examples
Write sumArray so that the following cases hold.
- Input
sumArray([1,2,3,4])Output10 - Input
sumArray([])Output0 - Input
sumArray([-5,5])Output0
1 more hidden test cases - 4 in total will be graded.
Answer
text
function sumArray(nums) {
return nums.reduce((total, n) => total + n, 0);
}
sumArray([1, 2, 3, 4]); // 10
