From: Robert Dober Date: 2009-07-29T21:11:45+09:00 Subject: Re: previous value in array block On Wed, Jul 29, 2009 at 10:50 AM, 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 } and purely functional ( [0] + a ).each_cons( 2 ).map{ |x,y| y -x } or with Tom's map arity trick implemented ( [0] + a ).map{ | x, y | y - x } > > -- Toutes les grandes personnes ont d’abord été des enfants, mais peu d’entre elles s’en souviennent. All adults have been children first, but not many remember. [Antoine de Saint-Exupéry]