ICE: adding consecutive elements in an array


I was hoping to do something more complicated, but I ran out of time…

Here’s the exercise: Take an array and build a new array by adding consecutive elements in the original array.
For example, given this array:

1 3 2 4 7 5 6 9 11 1 3 9

construct this array:

1+3, 3+2, 2+4, 4+7, ..., 3+9

array_sum_consecutive_elements

Summing up three consecutive elements will hopefully be more interesting…