`each_cons` in ruby to get differences
I want to get the difference between consecutive elements in an array. Ruby has a method each_cons
that provides a block with consecutive numbers of an enumerator.
[1, 3, 7].each_cons(2).map {|a, b| b - a }
=> [2, 4]
Tweet