Easy
Sum of an Array
Description
In this challenge, you are required to write a function that takes an array of numbers and returns the sum of all the elements.
Arrays are commonly used to store collections of data, and summing their values is a basic operation used in many real-world applications, such as calculating totals, averages, and financial figures.
Example Usage
sumArray([10, -5, 7]); // ➞ 12sumArray([]); // ➞ 0sumArray([100]); // ➞ 100
Constraints
- The input will always be an array of numbers.
- If the array is empty, return '0'.
- The array may contain both positive and negative numbers.
- The function should handle arrays of any length, including a single element.
Did you know?
TypeScript is not a language, it is a superset of JavaScript.
Test Cases
Input:
1
Expected Output:
15