Hi,

hash = {}
array1.uniq.each { |d| hash[d] = [] }
array1.each_with_index { |x,i| hash[x] << array2[i] }
hash.each_key { |key| hash[key] = hash[key].join('-') }
hash.inspect # => {"01/01/2009"=>"1stjan1-1stjan2-1stjan3",
"10/01/2009"=>"10thjan1-10thjan2"}

Enjoy,

-Harold
On Jan 27, 2:13 am, Shankar Ganesh <rails-mailing-l...@andreas-s.net>
wrote:
> Hi ,
>    I need to merge an array in ruby on rails.
>
>    array1 =
> ['01/01/2009','01/01/2009','10/01/2009','01/01/2009','10/01/2009']
>    array2 = ['1stjan1','1stjan2','10thjan1','1stjan3','10thjan2']
>
>    I need to have array like this
>
>    array3 =
> ['01/01/2009'=>'1stjan1-1stjan2-1stjan3','10/01/2009'=>'10thjan1-10thjan2']
>
>   Thanks in Advance.
> --
> 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@googlegroups.com
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to