nums = [2 5 3 7]
result = []
result.push {x:nums[0]}
for n in nums.slice(1)
result.push {n:n + result[-1].x}
log result
# [{x:2} {x:7} {x:10} {x:17}]
This is hard to express functionally using the function map
because each element depends on the previous element. What is the correct functional solution for this algorithm?