Sum of the Items in an Array

Published by Matt in

Create a function that takes an array and returns the sum of all the items in that array.

Examples

sum_arr([1, 2, 3]) ➞ 6
# 1 + 2 + 3 = 6

sum_arr([1, [2, [1]], 3]) ➞ 7
# 1 + 2 + 1 + 3 = 7

Notes

An item in the array can be another array.

Watch a quick demo on how Edabit works.