From: "Brian Schröder" Date: 2005-07-28T22:57:18+09:00 Subject: Re: Combination of two arrays On 28/07/05, Jim Freeze wrote: > * Claus Spitzer [2005-07-28 20:57:24 +0900]: > > > I have two arrays. let's call them foo and bar. > > foo = [ "a", "b", "c", ... n ] > > bar = [ 1 , 2 , 3 , ... m ] > > > > I am looking for a way to combine them such that the result is something like > > > > [ [ "a", 1 ], [ "a", 2 ], ... [ "a", m ], [ "b", 1 ], ... [ n, 1 ], > > ... [ n, m ] ] > > irb(main):002:0> foo = [ "a", "b", "c" ] > => ["a", "b", "c"] > irb(main):003:0> bar = [ 1 , 2 , 3 ] > => [1, 2, 3] > irb(main):004:0> foo.zip(bar) > => [["a", 1], ["b", 2], ["c", 3]] > That is not the same as what the OP was proposing. One could write the original approach using inject and shorten it one line by that approach, but that is more obfuscation than neccessary. I don't have any better proposal for Claus. regards, Brian -- http://ruby.brian-schroeder.de/ Stringed instrument chords: http://chordlist.brian-schroeder.de/