Jason Lillywhite wrote:
> 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
>

Another way could be:

a = [1,3,3,2]
b = [a[0]]

for i in 1...(a.length)
  b << (a[i] - a[i-1])
end

puts b

Not sure if that can be considered elegant though. :)

-DR
-- 
Posted via http://www.ruby-forum.com/.