On Dec 7, 2012, at 10:53 AM, Avantec Van wrote: > Hi All, > I have an array like this. > > [["question_7_pdx_0", ""], ["question_7_sdx_3", "4"], > ["question_7_cpt_2", ""], ["question_7_icd9px_0", ""], > ["question_7_sdx_0", "1"], ["question_7_sdx_8", ""], > ["question_7_sdx_11", ""], ["question_7_sdx_5", ""], > ["question_7_icd9px_2", ""], ["question_7_sdx_2", "3"], > ["question_7_cpt_1", ""], ["question_7_adx_0", ""], ["question_7_sdx_7", > ""], ["question_7_sdx_10", ""], ["question_7_sdx_4", ""], > ["question_7_icd9px_1", ""], ["question_7_sdx_1", "2"], > ["question_7_cpt_0", ""], ["question_7_sdx_9", ""], > ["question_7_sdx_12", ""], ["question_7_sdx_6", ""]] > > > I want this array to sort like this. > > [["question_7_adx_0", ""], ["question_7_cpt_0", ""], > ["question_7_cpt_1", ""], ["question_7_cpt_2", ""], > ["question_7_icd9px_0", ""], ["question_7_icd9px_1", ""], > ["question_7_icd9px_2", ""], ["question_7_pdx_0", ""], > ["question_7_sdx_0", "1"], ["question_7_sdx_1", "2"], > ["question_7_sdx_2", "3"], ["question_7_sdx_3", "4"], > ["question_7_sdx_4", ""], ["question_7_sdx_5", ""], ["question_7_sdx_6", > ""], ["question_7_sdx_7", ""], ["question_7_sdx_8", ""], > ["question_7_sdx_9", ""], ["question_7_sdx_10", ""], > ["question_7_sdx_11", ""], ["question_7_sdx_12", ""]] > > Please help me. >
The first question I would have is, how did you get this array in the first place? If it's the output from an ActiveRecord query, then you could most profitably sort there in the data-gathering stage. Otherwise, if you redefine your sort method (or use a custom sort method) then you should be able to sort by the value of index 0 of each sub-array, right? Walter > Thanks in advance, > Avantec > > -- > Posted via http://www.ruby-forum.com/. > > -- > You received this message because you are subscribed to the Google Groups > "Ruby on Rails: Talk" group. > To post to this group, send email to [email protected]. > To unsubscribe from this group, send email to > [email protected]. > For more options, visit https://groups.google.com/groups/opt_out. > > -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit https://groups.google.com/groups/opt_out.

