From: Robert Dober Date: 2009-07-29T21:12:52+09:00 Subject: Re: previous value in array block On Wed, Jul 29, 2009 at 12:56 PM, David A. Black wrote: > Hi -- > > On Wed, 29 Jul 2009, Xavier Noria wrote: > >> each_cons seems natural here: >> >> require 'enumerator' >> >> a = [1, 3, 3, 2] >> b = a[0, 1] >> >> a.each_cons(2) { |x, y| b << y - x } > > Here's a 1.9 way, probably guilty of gross wasteage (by creating an > extra new array) but kind of cool: > > [0,*a].each_cons(2).map {|x,y| y - x } A beauty, sorry did not see it before my post! Cheers Robert