Jason Lillywhite wrote: > Is this a good way to use a previous value in an array block? > > I want to subtract the item(i) from item(i-1) of the array, a and return > a new array of the results. Below is my attempt. > > a = [1,3,3,2] > prev_item = 0 > b = [] > > a.each do |item| > b << item - prev_item > prev_item = item > end > > puts b > > => 1,2,0,-1 > > I'm thinking there must be a more elegant way of doing this. > > thank you! I was recently reading through the facets docuementation and so thought I would develop a solution for the OP using the elementwise method that facets supplies. However while other facets methods from enumerable are available, elementwise does not seem to be. C:\Documents and Settings\Administrator>irb irb(main):001:0> a=Array.new => [] irb(main):002:0> a.respond_to?("elementwise") => false irb(main):003:0> a.respond_to?("entropy") => false irb(main):004:0> require "facets" => true irb(main):005:0> a.respond_to?("entropy") => true irb(main):006:0> a.respond_to?("elementwise") => false I am using windows xp, one click Ruby 186-26 and facets 2.5.0. Can some kind person point out my error? Thanks Steve