From: Harry Kakueki Date: 2007-07-22T15:04:42+09:00 Subject: Re: Method to return elements of an array in numeric 'rank'? On 7/22/07, Jenny Purcell wrote: > > It looks like you're suggesting a two dimensional array, is that > correct? I think that would also work, although I'm not quite good > enough with Ruby syntax (or arrays) to follow it 100%. > > Jenny > > What I'm thinking is that you could set up a 2D array and sort it on the scores (element [1] of each sub-array). Then you can extract the data you want. You can do it using only arrays, which I think you said you wanted to do. This is not a total solution, just an idea. arr = [[1,7],[3,2],[4,9],[2,3]] # [horse,score],[horse,score] etc.] arr.sort! {|x,y| y[1] <=> x[1]} p arr #> [[4,9],[1,7],[2,3],[3,2]] puts p arr[0] #>[4,9] p arr[1] #>[1,7] p arr[2] #>[2,3] puts p arr[0][0] #> 4 p arr[0][1] #> 9 p arr[1][0] #> 1 p arr[1][1] #> 7 Harry -- A Look into Japanese Ruby List in English http://www.kakueki.com/