Add Array Elements
easySave
ArrayMath
Given an array of numbers, return the sum of all elements in the array.
Example 1
Input
[ 1, 2, 3 ]
Output
6
Explanation. The sum of 1 + 2 + 3 is 6.
Example 2
Input
[ 0, 0, 0, 0 ]
Output
0
Explanation. The sum of 0 + 0 + 0 + 0 is 0.
Example 3
Input
[ -5, 100, 40, 3 ]
Output
138
Explanation. The sum of -5 + 100 + 40 + 3 is 138.
Follow-up: How would you modify your solution to handle arrays that contain floating point numbers or integers?
Constraints:
The array will contain at least one element and all elements will be integers.
- Views
- 2