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 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 -~----------~----~----~----~------~----~------~--~---
Haii... I will try help u. array3 [''01/01/2009''=>''1stjan1-stjan2-1stjan3'',''10/01/2009''=>''10thjan1-10thjan2''] -> *this is not array.. this is hash..* The code is array3 = {} array1.each_with_index do |x, i| array3[x] = array2[i] end may be it can help u.. thank you.. fyi ==> array1.length == array2.length --> this is rule for that case....( *MUST*) On Tue, Jan 27, 2009 at 2:13 PM, Shankar Ganesh < rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> 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 via http://www.ruby-forum.com/. > > > >-- Wu You Duan --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
hi, I''m getting value like {"1stjan1"=>"01/01/2009", "10thjan1"=>"10/01/2009", "1stjan2"=>"01/01/2009",and so} for the code array3 = {} array1.each_with_index do |x, i| array3[x] = array2[i] end I need to merge the value but the key(date) should be same. Thanks. anton effendi wrote:> Haii... > I will try help u. > array3 > [''01/01/2009''=>''1stjan1-stjan2-1stjan3'',''10/01/2009''=>''10thjan1-10thjan2''] > -> *this is not array.. this is hash..* > > The code is > array3 = {} > array1.each_with_index do |x, i| > array3[x] = array2[i] > end > > > may be it can help u.. > thank you.. > > fyi ==> array1.length == array2.length --> this is rule for that > case....( > *MUST*) > > > > On Tue, Jan 27, 2009 at 2:13 PM, Shankar Ganesh < > rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote: > >> array3 >> [''01/01/2009''=>''1stjan1-1stjan2-1stjan3'',''10/01/2009''=>''10thjan1-10thjan2''] >> >> Thanks in Advance. >> -- >> Posted via http://www.ruby-forum.com/. >> >> > >> > > > -- > Wu You Duan-- 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 -~----------~----~----~----~------~----~------~--~---
make sure..... array1 --> date array2 --> the value... or array3 = {} array1.each_with_index do |x, i| array3[x] = array2[i] end change to array3 = {} array2.each_with_index do |x, i| array3[x] = array1[i] end please try again On Tue, Jan 27, 2009 at 3:56 PM, Shankar Ganesh < rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > > hi, > I''m getting value like {"1stjan1"=>"01/01/2009", > "10thjan1"=>"10/01/2009", "1stjan2"=>"01/01/2009",and so} > for the code > > array3 = {} > array1.each_with_index do |x, i| > array3[x] = array2[i] > end > > I need to merge the value but the key(date) should be same. > > Thanks. > > anton effendi wrote: > > Haii... > > I will try help u. > > array3 > > > [''01/01/2009''=>''1stjan1-stjan2-1stjan3'',''10/01/2009''=>''10thjan1-10thjan2''] > > -> *this is not array.. this is hash..* > > > > The code is > > array3 = {} > > array1.each_with_index do |x, i| > > array3[x] = array2[i] > > end > > > > > > may be it can help u.. > > thank you.. > > > > fyi ==> array1.length == array2.length --> this is rule for that > > case....( > > *MUST*) > > > > > > > > On Tue, Jan 27, 2009 at 2:13 PM, Shankar Ganesh < > > rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote: > > > >> array3 > >> > [''01/01/2009''=>''1stjan1-1stjan2-1stjan3'',''10/01/2009''=>''10thjan1-10thjan2''] > >> > >> Thanks in Advance. > >> -- > >> Posted via http://www.ruby-forum.com/. > >> > >> > > >> > > > > > > -- > > Wu You Duan > > -- > Posted via http://www.ruby-forum.com/. > > > >-- Wu You Duan --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
<% array1 =[''01/01/2009'',''01/01/2009'',''10/01/2009'',''01/01/2009'',''10/01/2009''] %> <%array2 = [''1stjan1'',''1stjan2'',''10thjan1'',''1stjan3'',''10thjan2'']%> <%array3 = {} %> <%array2.each_with_index do |x, i|%> <%array3[x] = array1[i]%> <%end%> <br> <%=array3.inspect %> I''m getting o/p like this {"1stjan1"=>"01/01/2009", "10thjan1"=>"10/01/2009", "1stjan2"=>"01/01/2009", "10thjan2"=>"10/01/2009", "1stjan3"=>"01/01/2009"} anton effendi wrote:> make sure..... > array1 --> date > array2 --> the value... > > or > array3 = {} > array1.each_with_index do |x, i| > array3[x] = array2[i] > end > > change to > > array3 = {} > array2.each_with_index do |x, i| > array3[x] = array1[i] > end > > please try again > > On Tue, Jan 27, 2009 at 3:56 PM, Shankar Ganesh < > rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote: > >> end >> [''01/01/2009''=>''1stjan1-stjan2-1stjan3'',''10/01/2009''=>''10thjan1-10thjan2''] >> > thank you.. >> >> array3 >> > >> > -- >> > Wu You Duan >> >> -- >> Posted via http://www.ruby-forum.com/. >> >> > >> > > > -- > Wu You Duan-- 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 -~----------~----~----~----~------~----~------~--~---
send to me the file.. I will repair... I think use: array3 = {} array1.each_with_index do |x, i| array3[x] = array2[i] end On Tue, Jan 27, 2009 at 8:50 PM, Shankar Ganesh < rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > > <% array1 > =[''01/01/2009'',''01/01/2009'',''10/01/2009'',''01/01/2009'',''10/01/2009''] %> > <%array2 = [''1stjan1'',''1stjan2'',''10thjan1'',''1stjan3'',''10thjan2'']%> > <%array3 = {} %> > <%array2.each_with_index do |x, i|%> > <%array3[x] = array1[i]%> > <%end%> > <br> > <%=array3.inspect %> > > I''m getting o/p like this > > > {"1stjan1"=>"01/01/2009", "10thjan1"=>"10/01/2009", > "1stjan2"=>"01/01/2009", "10thjan2"=>"10/01/2009", > "1stjan3"=>"01/01/2009"} > > > > > anton effendi wrote: > > make sure..... > > array1 --> date > > array2 --> the value... > > > > or > > array3 = {} > > array1.each_with_index do |x, i| > > array3[x] = array2[i] > > end > > > > change to > > > > array3 = {} > > array2.each_with_index do |x, i| > > array3[x] = array1[i] > > end > > > > please try again > > > > On Tue, Jan 27, 2009 at 3:56 PM, Shankar Ganesh < > > rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote: > > > >> end > >> > [''01/01/2009''=>''1stjan1-stjan2-1stjan3'',''10/01/2009''=>''10thjan1-10thjan2''] > >> > thank you.. > >> >> array3 > >> > > >> > -- > >> > Wu You Duan > >> > >> -- > >> Posted via http://www.ruby-forum.com/. > >> > >> > > >> > > > > > > -- > > Wu You Duan > > -- > Posted via http://www.ruby-forum.com/. > > > >-- Wu You Duan --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
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...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
hi, Thank you DUDE it works ! Harold wrote:> 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>-- 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Hi, I got a table like this -- 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 -~----------~----~----~----~------~----~------~--~---
Hi, I got a table like this --------------------------------------------------------------- id | what | when | color | to | description | --------------------------------------------------------------- 1 | test |01/01/2009 | red |04/01/2009 | hi this is test | --------------------------------------------------------------- 2 | test2 |02/01/2009 | green |04/01/2009 | hi this is test | --------------------------------------------------------------- 3 | test3 |01/01/2009 | blue |04/01/2009 | hi this is test | --------------------------------------------------------------- 4 | test4 |02/01/2009 | orange |04/01/2009 | hi this is test | --------------------------------------------------------------- I had fetch the value from the database in such a way like this ############################## #[JavaScript source with ROR]# ############################## var dAb = new Array(); var x = 0; var event_task_today =''''; var event_task =''''; <% @eventall.each do |d| %> var DBdate1 = ''<%= d.when%>''; var eventdate1 = DBdate1.split(''/''); var task_date1 =eventdate1[2]+eventdate1[1]+eventdate1[0]; dAb[x++] = task_date1+" <div align=''lef'' style=''background:<%=d.color%>;color:white;''><%= d.what%></div>"; <% end %> If I alert ''dAb''value I''m getting like this ***** 20090101 <div align=''left'' style=''background:red;color:white;''>test</div>,20090102 <div align=''left'' style=''background:green;color:white;''>test2</div>,20090101 <div align=''left'' style=''background:blue;color:white;''>test3</div>,20090102 <div align=''left'' style=''background:orange;color:white;''>test4</div> I need to have JavaScript variable ''dAb''like this ******** 20090101 <div align=''left'' style=''background:red;color:white;''>test</div><BR><div align=''left'' style=''background:blue;color:white;''>test3</div>,20090102 <div align=''left'' style=''background:green;color:white;''>test2</div><BR><div align=''left'' style=''background:orange;color:white;''>test4</div> <BR> tag should be placed in between the values with same date ,date should be printed only once. PLEASE ADVICE. Thanks in advance. -- 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 -~----------~----~----~----~------~----~------~--~---
Which record do you want to include for the repeated dates? the first, or last? Julian http://sensei.zenunit.com/ http://random8.zenunit.com/ On 28/01/2009, at 1:50 PM, Shankar Ganesh wrote:> > Hi, > > I got a table like this > > --------------------------------------------------------------- > id | what | when | color | to | description | > --------------------------------------------------------------- > 1 | test |01/01/2009 | red |04/01/2009 | hi this is test | > --------------------------------------------------------------- > 2 | test2 |02/01/2009 | green |04/01/2009 | hi this is test | > --------------------------------------------------------------- > 3 | test3 |01/01/2009 | blue |04/01/2009 | hi this is test | > --------------------------------------------------------------- > 4 | test4 |02/01/2009 | orange |04/01/2009 | hi this is test | > --------------------------------------------------------------- > > I had fetch the value from the database in such a way like this > > ############################## > #[JavaScript source with ROR]# > ############################## > > var dAb = new Array(); > var x = 0; > var event_task_today =''''; > var event_task =''''; > > <% @eventall.each do |d| %> > var DBdate1 = ''<%= d.when%>''; > var eventdate1 = DBdate1.split(''/''); > var task_date1 =eventdate1[2]+eventdate1[1]+eventdate1[0]; > dAb[x++] = task_date1+" <div align=''lef'' > style=''background:<%=d.color%>;color:white;''><%= d.what%></div>"; > <% end %> > > If I alert ''dAb''value I''m getting like this > ***** > > 20090101 <div align=''left'' > style=''background:red;color:white;''>test</div>,20090102 <div > align=''left'' style=''background:green;color:white;''>test2</div>, > 20090101 > <div align=''left'' > style=''background:blue;color:white;''>test3</div>,20090102 <div > align=''left'' style=''background:orange;color:white;''>test4</div> > > I need to have JavaScript variable ''dAb''like this > ******** > > 20090101 <div align=''left'' > style=''background:red;color:white;''>test</div><BR><div align=''left'' > style=''background:blue;color:white;''>test3</div>,20090102 <div > align=''left'' style=''background:green;color:white;''>test2</div><BR><div > align=''left'' style=''background:orange;color:white;''>test4</div> > > <BR> tag should be placed in between the values with same date ,date > should be printed only once. > > PLEASE ADVICE. > > Thanks in advance. > > -- > 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 -~----------~----~----~----~------~----~------~--~---
all the records should be included. Julian Leviston wrote:> Which record do you want to include for the repeated dates? the first, > or last? > > Julian > > http://sensei.zenunit.com/ > http://random8.zenunit.com/-- 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 -~----------~----~----~----~------~----~------~--~---