From: Colin Bartlett Date: 2010-11-30T01:33:09+09:00 Subject: Re: Help sorting an array --0016363b85a0844224049633a0ad Content-Type: text/plain; charset=ISO-8859-1 On Mon, Nov 29, 2010 at 4:25 PM, Su Zhang wrote: > > Looking forward to seeing better solutions :) Well this is different, but I'm not sure it's better. :) I suspect your version may be more robust (or at least easier to fix) if the data doesn't end with a String (month). ary = [ 1, 2, "MARCH", 3, 4, "FEBRUARY", 5, "JANUARY" ] p ary ary_new = [] ii = 0 ary.each_with_index do |ee, jj| if ee.kind_of?( String ) then ary_new << ee (ii .. (jj - 1)).each { |i| ary_new << ary[ i ] } ii = jj + 1 end end ary.replace( ary_new ) p ary --0016363b85a0844224049633a0ad--