From: w_a_x_man@... Date: 2009-02-13T03:23:45+09:00 Subject: Re: Arrays and Hashes processing :pls help On Feb 12, 10:58 am, Jags Rao wrote: > hi friends > > i have a long array with structure like this > > [["377", "838"], >  ["377", "990"], >  ["377", "991"], >  ["377", "992"], >  ["378", "840"], >  ["378", "841"], >  ["378", "842"], >  ["378", "843"], >  ["378", "844"]] > > how can i convert it in one line to > > [["377", "838 990 991 992"], >  ["378", "840 841 842 843 844"]] > > if thats diificult is the below array processable in one line > > [{"prefix"=>"838", "scf_id"=>"377"}, >  {"prefix"=>"990", "scf_id"=>"377"}, >  {"prefix"=>"991", "scf_id"=>"377"}, >  {"prefix"=>"992", "scf_id"=>"377"}, >  {"prefix"=>"840", "scf_id"=>"378"}, >  {"prefix"=>"841", "scf_id"=>"378"}, >  {"prefix"=>"842", "scf_id"=>"378"}, >  {"prefix"=>"843", "scf_id"=>"378"}, >  {"prefix"=>"844", "scf_id"=>"378"}] > > in this form > > [{"prefix"=>"838 990 991 992", "scf_id"=>"377"}, >  {"prefix"=>"840 841 842 843 844", "scf_id"=>"378"}] > > pls help > Jags > -- > Posted viahttp://www.ruby-forum.com/. a = [["377", "838"], ["377", "990"], ["377", "991"], ["377", "992"], ["378", "840"], ["378", "841"], ["378", "842"], ["378", "843"], ["378", "844"]] h=Hash.new{[]};a.each{|x,y|h[x]+=[y]};h.map{|x,y|[x,y.join(" ")]} ==>[["377", "838 990 991 992"], ["378", "840 841 842 843 844"]]