agemoagemo / yahoo.com wrote: > --- Robert Klemme <bob.news / gmx.net> wrote: >>> %w{aa bb cc dd ee ff gg hh ii jj >> kk}.each_window(3) {|*a| p a} >> ["aa", "bb", "cc"] >> ["bb", "cc", "dd"] >> ["cc", "dd", "ee"] >> ["dd", "ee", "ff"] >> ["ee", "ff", "gg"] >> ["ff", "gg", "hh"] >> ["gg", "hh", "ii"] >> ["hh", "ii", "jj"] >> ["ii", "jj", "kk"] >> => ["aa", "bb", "cc", "dd", "ee", "ff", "gg", "hh", >> "ii", "jj", "kk"] > > Am I the only one who thinks this seems a little > peculiar? > > If I were writing something using this sort of > functionality, I think I'd need and expect > output something like: > > [nil, "aa", "bb"] > ["aa", "bb", "cc"] > ["bb", "cc", "dd"] > ["cc", "dd", "ee"] > ["dd", "ee", "ff"] > ["ee", "ff", "gg"] > ["ff", "gg", "hh"] > ["gg", "hh", "ii"] > ["hh", "ii", "jj"] > ["ii", "jj", "kk"] > ["jj", "kk", nil] Well, it depends. If, for example, you would want to make a plot that used averaged values (i.e. to smooth the curve) you would not want to see those lines containing nil values IMHO. > Admittedly, it'd be hard to that reasonably with a > variable-size window of even length. But for a > previous-current-next arrangement, it seems to make > more sense to say "there is no previous" with a nil > than to basically skip the first item. It's not that hard to do. Kind regards robert