From: Joel VanderWerf Date: 2009-06-18T07:44:48+09:00 Subject: Re: new-b question David Newton wrote: > I am trying to calculate a 5 day weighted moving average based on a set > of numbers in a data series. The most recent is given a * 5 weight, the > next * 4 etc etc. with the oldest (the 5th number) * 1. Does this help? You will need to handle the edge cases somehow... $ ri Enumerable#each_cons | cat --------------------------------------------------- Enumerable#each_cons each_cons(n) {...} From Ruby 1.8 ------------------------------------------------------------------------ Iterates the given block for each array of consecutive elements. e.g.: (1..10).each_cons(3) {|a| p a} # outputs below [1, 2, 3] [2, 3, 4] [3, 4, 5] [4, 5, 6] [5, 6, 7] [6, 7, 8] [7, 8, 9] [8, 9, 10] -- vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407