Skip to main content

Sum an Array (JavaScript)

Easy

Complete the reduce call so it returns the sum of all numbers in the array.

const nums = [1, 2, 3, 4];
const total = nums.((acc, n) => acc  n, 0);
console.log(total); // 10
Need a hint?

Which array method accumulates a single value? And which operator adds?