How can I create a new array for summing array elements in place in Ruby?
[1,2,3,4,5].each_cons(2).map {|a, b| a + b }
gives me [3, 5, 7,
[3, 5, 7,
[1, 2, 3, 4, 5].each_with_object([]){|e, a| a.push(a.last.to_i + e)} # => [1, 3, 6, 10, 15]