← All Exercises
Array Sum Calculator
basicjavascript
Background
Summing arrays is a fundamental operation in programming, used in statistics, finance, and data processing tasks.
Problem
Given an array of numbers, write a function that returns the sum of all elements. Handle empty arrays by returning zero.
Input
An array of zero or more numbers (integers or floats).
Output
A single number representing the sum of all array elements.
Sample tests
Sample 1
Input: [1, 2, 3, 4, 5]
Expected: 15
Your solution
Learning objective
Learn to use Array.prototype.reduce for aggregating values in a functional programming style.