From: Lars Haugseth Date: 2012-06-26T17:58:37+09:00 Subject: Re: working with two arrays On 06/26/2012 05:25 AM, Avdi Grimm wrote: > On Mon, Jun 25, 2012 at 9:06 PM, skolo pen > wrote: > > What method could I use to do the following: > > people = ["person1","person2","person3"] > > issue = ["issue1","issue2","issue3","issue4","issue5","issue6"] > > person1 => issue1 > > person2 => issue2 > > person3 => issue3 > > person1 => issue4 > > person2 => issue5 > > person3 => issue6 > > > people.cycle.take(issue.size).zip(issue) Nice! > Note that this will produce an array of arrays. A Hash doesn't work for > this because any given key can only appear once. Hash[people.each_with_index.map {|p, i| [p, i.step(issue.size - 1, people.size).map {|j| issue[j]}] }] => {"person1"=>["issue1", "issue4"], "person2"=>["issue2", "issue5"], "person3"=>["issue3", "issue6"]} -- Lars Haugseth