# Sorting through array?

**URL:** <https://www.ruby-forum.com/t/sorting-through-array/140352>\
**Category:** Rails\
**Created:** [June 13, 2008, 6:18am UTC](https://www.ruby-forum.com/t/sorting-through-array/140352 "2008-06-13T06:18:55Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![GabrielG1976](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/8491ac/32.png) [@GabrielG1976](https://www.ruby-forum.com/u/GabrielG1976)\
**Post date:** [June 13, 2008, 6:18am UTC](https://www.ruby-forum.com/t/sorting-through-array/140352/1 "2008-06-13T06:18:55Z")

</div>

I have a sorting and collecting question say i have a array with 18  
elements and each element is storing 5 numbers  
i want to collect each of the 5 numbers out of the that index of the  
array and store there values into different arrays what would be the  
easiest and dryest way of complete this task

example array[0…18]  
array[0] =\> [1 2 3 4 5]

thanks for any help

Gabriel G

---

<div class="post-metadata">

**Author:** ![GabrielG1976](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/8491ac/32.png) [@GabrielG1976](https://www.ruby-forum.com/u/GabrielG1976)\
**Post date:** [June 13, 2008, 11:11am UTC](https://www.ruby-forum.com/t/sorting-through-array/140352/2 "2008-06-13T11:11:32Z")

</div>

GabrielG1976 wrote:

> I have a sorting and collecting question say i have a array with 18  
> elements and each element is storing 5 numbers  
> i want to collect each of the 5 numbers out of the that index of the  
> array and store there values into different arrays what would be the  
> easiest and dryest way of complete this task
> 
> example array[0…18]  
> array[0] =\> [1 2 3 4 5]
> 
> thanks for any help
> 
> Gabriel G

“store their values into different arrays” - can you supply more details  
about what you want to do with the numbers?

---

<div class="post-metadata">

**Author:** ![GabrielG1976](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/8491ac/32.png) [@GabrielG1976](https://www.ruby-forum.com/u/GabrielG1976)\
**Post date:** [June 13, 2008, 7:01pm UTC](https://www.ruby-forum.com/t/sorting-through-array/140352/3 "2008-06-13T19:01:01Z")

</div>

What it is a Golf score keeper each of the game[0…17] array elements  
is a round or 1 hole in golf  
the first number is what par is and each of the 4 golfers strokes  
taken at that hole game[0] =\> [1 2 3 4 5]

---

<div class="post-metadata">

**Author:** ![GabrielG1976](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/8491ac/32.png) [@GabrielG1976](https://www.ruby-forum.com/u/GabrielG1976)\
**Post date:** [June 13, 2008, 10:24pm UTC](https://www.ruby-forum.com/t/sorting-through-array/140352/4 "2008-06-13T22:24:35Z")

</div>

GabrielG1976 wrote:

> What it is a Golf score keeper each of the game[0…17] array elements  
> is a round or 1 hole in golf  
> the first number is what par is and each of the 4 golfers strokes  
> taken at that hole game[0] =\> [1 2 3 4 5]

what about something like (I assume you want five arrays out of this)  
If round is your starting array like [[4, 4, 3, 4, 5],[4, 4, 4, 4,  
5],[3, 2, 3, 3, 4],…] (yeah, that last golfer must be me)

par = []  
golfer1 = []  
golfer2 = []  
golfer3 = []  
golfer4 = []  
round.each do |scores|  
par \<\< scores[0]  
golfer1 \<\< scores[1]  
etc  
end

I’m sure there’s a more cryptographic way to do it that takes less  
keystrokes, but I value clarity.

---

<div class="post-metadata">

**Author:** ![GabrielG1976](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/8491ac/32.png) [@GabrielG1976](https://www.ruby-forum.com/u/GabrielG1976)\
**Post date:** [June 14, 2008, 2:25am UTC](https://www.ruby-forum.com/t/sorting-through-array/140352/5 "2008-06-14T02:25:10Z")

</div>

Thanks  
for everyones help

Gabriel
