I\'d like a function runningSum on an array of numbers a (or any ordered collection of addable things) that returns an array of the same length where each eleme
runningSum
Assuming an array of Ints, sounds like you can use map to manipulate the input:
Int
map
let arr = [0,1,0,1,0,1] var sum = 0 let val = arr.map { (sum += $0, sum).1 } print(val) // "[0, 1, 1, 2, 2, 3]\n"
I'll keep working on a solution that doesn't use an external variable.