From: Rob Biedenharn Date: 2008-09-22T22:25:01+09:00 Subject: Re: Merging two arrays On Sep 22, 2008, at 9:02 AM, Chris Chris wrote: > Hi, > > in Ruby, I have two arrays: > > products = Array.new > products << ["Amazon",121212,"Harry Potter"] > products << ["Amazon",242424,"John Grisham"] > products << ["Amazon",353535,"Michael Crichton"] > > links = Array.new > links << [121212,"www.amazon.com/abc"] > links << [242424,"www.amazon.com/johngrisham"] > links << [353535,"www.amazon.com/somelink"] > > I would like to merge these two arrays. The article number is to be > the > identifier. > > Thus, I would like an array like this as the result: > ["Amazon",121212,"Harry Potter","www.amazon.com/abc"] > > Any help greatly appreciated. > > Cheers, Chris Treat links as an associative array, and use something like: products.collect! {|p| p << links.assoc(p[1])[1] } I.e., look at the docs for Array#assoc -Rob Rob Biedenharn http://agileconsultingllc.com Rob@AgileConsultingLLC.com