Sum of Array

Given a function that takes an array as an argument and returns the sum of its elements.

Example 1

Input: sum([1, 2, 3, 4])

Output: 10

Example 2

Input: sum([])

Output: 0

Ever came across this question in a real interview?
Available Hints
Think of using loops
Use the reduce function to accumulate the sum of the array. Initialize the accumulator with 0.
Loading editor...