Ruby 1.8.6
I have an array containing numerical values. I want to reduce it such that sequences of the same value are reduced to a single instance of that value.
another solution:
acc = [a[0]] a.each_cons(2) {|x,y| acc << y if x != y}
or
a.each_cons(2).inject([a[0]]) {|acc, (x,y)| x == y ? acc : acc << y}