# Array1 + array2 newb question

**URL:** <https://rubytalk.org/t/array1-array2-newb-question/21528>\
**Category:** ruby-talk\
**Created:** [13 October 2005 07:32 UTC](https://rubytalk.org/t/array1-array2-newb-question/21528 "2005-10-13T07:32:27Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kroeger\_Simon\_ext](https://avatars.discourse-cdn.com/v4/letter/k/5daacb/32.png) [@Kroeger\_Simon\_ext](https://rubytalk.org/u/Kroeger_Simon_ext)\
**Post date:** [13 October 2005 07:32 UTC](https://rubytalk.org/t/array1-array2-newb-question/21528/1 "2005-10-13T07:32:27Z")

</div>

It's not so obviously,

a1.inject(){|s, x| s + a2.map {|y| [x, y]}}

cheers

Simon

> **···**
>
> > -----Original Message-----  
> > From: Mike Schramm [mailto:mike@mikeschramm.com]  
> > Sent: Thursday, October 13, 2005 5:39 AM  
> > To: ruby-talk ML  
> > Subject: array1 + array2 newb question
> > 
> > Hey all,
> > 
> > I'm a ruby newbie, so this will be obvious, but I can't figure it out.
> > 
> > I'm trying to create a map grid from arrayed names of streets. I  
> > want to go from [1,2,3] and [a,b,c] to [[1,a], [2,a], [3,a],  
> > [1,b],... [3,c]].
> > 
> > so far the closest I have gotten is
> > 
> > a1.collect!{|x| [x, a2.collect!{|y| y}]}
> > 
> > which returns-- well you can try it if you like, but it's not  
> > right.  
> > Instead of just returning one value of a2 at a time, it returns the  
> > whole thing every time. I'm guessing I need to somehow cycle  
> > through  
> > each element of a2 (ie a2[0], a2[1], a2[2]), but I can't  
> > figure it out.
> > 
> > You guys will probably eat this up. What am I so obviously  
> > doing wrong?
> > 
> > Mike
