Hi I have very silly doubt in Array and hash? My hash value is -- ''community''=>{"108"=>"", "94"=>"12345204", "95"=>"selvaraj-2o7tMWoZLqmm1FQbPH9wZw@public.gmane.org", "96"=>"blore"} After that i have taken only keys from this hash params[:community].keys Result I am getting as Arry---> ["108", "94", "95", "96"] Can I use ["108", "94", "95", "96"].sort Its not working for me.... Because I want only key value with sorted order.. -- 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
your array contains strings, and when you sort strings, the output will be ["108", "94", "95", "96"] but when you convert array elements into integers and sort after that, you must get [94,95,96,108] --~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Thanks Ivanov, Its working fine. Actually I convert each element into integer,Then i form arry with thiose element. Ilja Ivanov wrote:> your array contains strings, and when you sort strings, the output > will be ["108", "94", "95", "96"] > but when you convert array elements into integers and sort after that, > you must get [94,95,96,108]-- 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
roland.mai-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2007-Jun-03 12:28 UTC
Re: Trouble in Array sort?
Here''s how you could do it: params[:community].keys.sort_by{|k| k.to_i} On Jun 3, 6:02 am, Selvaraj <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> Thanks Ivanov, > > Its working fine. > Actually I convert each element into integer,Then i form arry with > thiose element. > > Ilja Ivanov wrote: > > your array contains strings, and when you sort strings, the output > > will be ["108", "94", "95", "96"] > > but when you convert array elements into integers and sort after that, > > you must get [94,95,96,108] > > -- > Posted viahttp://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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---