Hi, [b]is there any method to merge one array values in to another array, i mean i have a different situation here. There are 2 instance variables and generating output like this :[/b] [code=]@users_count = [["Feb 2008", 1], ["Mar 2008", 3], ["Apr 2008", 5], ["May 2008", 5], ["Jun 2008", 3], ["Jul 2008", 2], ["Aug 2008", 1]] @customers_count = [["Mar 2008", 6], ["Apr 2008", 8], ["May 2008", 6], ["Jun 2008", 9]] i want to merge one array in to another to look like : @chart_data = [["Feb 2008", 1], ["Mar 2008", 3, 6], ["Apr 2008", 5, 8], ["May 2008", 5, 6], ["Jun 2008", 3, 9], ["Jul 2008", 2], ["Aug 2008", 1]][/code] [b] this type of data is required to pass and display for a fusion chart representing 2 different lines with values on chart and month names on bottom, i know this would be a strange case....[/b] any help ?? thanks -- 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 -~----------~----~----~----~------~----~------~--~---
I think the method you''re looking for is zip. @users_count.zip(@customers_count) On 01/08/2008, at 7:53 PM, Srinath A. wrote:> > Hi, > > [b]is there any method to merge one array values in to another > array, i > mean i have a different situation here. > There are 2 instance variables and generating output like this :[/b] > [code=]@users_count = [["Feb 2008", 1], ["Mar 2008", 3], ["Apr 2008", > 5], ["May 2008", 5], ["Jun 2008", 3], ["Jul 2008", 2], ["Aug 2008", > 1]] > @customers_count = [["Mar 2008", 6], ["Apr 2008", 8], ["May 2008", 6], > ["Jun 2008", 9]] > > i want to merge one array in to another to look like : > @chart_data = [["Feb 2008", 1], ["Mar 2008", 3, 6], ["Apr 2008", 5, > 8], > ["May 2008", 5, 6], ["Jun 2008", 3, 9], ["Jul 2008", 2], ["Aug 2008", > 1]][/code] > [b] > this type of data is required to pass and display for a fusion chart > representing 2 different lines with values on chart and month names on > bottom, i know this would be a strange case....[/b] > > > any help ?? > thanks > -- > 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 -~----------~----~----~----~------~----~------~--~---
David A. Black wrote:> Hi -- > > > On Fri, 1 Aug 2008, Ryan Bigg wrote: > >>> 5], ["May 2008", 5], ["Jun 2008", 3], ["Jul 2008", 2], ["Aug 2008", >>> this type of data is required to pass and display for a fusion chart >>> representing 2 different lines with values on chart and month names on >>> bottom, i know this would be a strange case....[/b] >>> >>> >>> any help ?? >>> thanks >> >> I think the method you''re looking for is zip. >> >> @users_count.zip(@customers_count) > > No, that doesn''t produce the desired result. > > > David > > -- > Rails training from David A. Black and Ruby Power and Light: > * Advancing With Rails August 18-21 Edison, NJ > * Co-taught by D.A. Black and Erik Kastner > See http://www.rubypal.com for details and updates!Hi David, yep you are right !! Great and Thanks a lot for Replying, it works fantastic in my application and what about if we have third variable say @products_count, can we merge this too -- 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 -- On Fri, 1 Aug 2008, Srinath A. wrote:> > David A. Black wrote: >> Hi -- >> >> >> On Fri, 1 Aug 2008, Ryan Bigg wrote: >> >>>> 5], ["May 2008", 5], ["Jun 2008", 3], ["Jul 2008", 2], ["Aug 2008", >>>> this type of data is required to pass and display for a fusion chart >>>> representing 2 different lines with values on chart and month names on >>>> bottom, i know this would be a strange case....[/b] >>>> >>>> >>>> any help ?? >>>> thanks >>> >>> I think the method you''re looking for is zip. >>> >>> @users_count.zip(@customers_count) >> >> No, that doesn''t produce the desired result. >> >> >> David >> >> -- >> Rails training from David A. Black and Ruby Power and Light: >> * Advancing With Rails August 18-21 Edison, NJ >> * Co-taught by D.A. Black and Erik Kastner >> See http://www.rubypal.com for details and updates! > > Hi David, yep you are right !! > Great and Thanks a lot for Replying, it works fantastic in my > application > and what about if we have third variable say @products_count, can we > merge this > tooOf course. But I shall leave that as an exercise to the reader :-) The techniques you need should be present in the two-array example. David -- Rails training from David A. Black and Ruby Power and Light: * Advancing With Rails August 18-21 Edison, NJ * Co-taught by D.A. Black and Erik Kastner See http://www.rubypal.com for details and updates! --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
I would just use the union method on the Array class: http://www.ruby-doc.org/core/classes/Array.html#M000325>> users_count = [["Feb 2008", 1], ["Mar 2008", 3], ["Apr 2008", 5], ["May 2008", 5], ["Jun 2008", 3], ["Jul 2008", 2], ["Aug 2008", 1]]=> [["Feb 2008", 1], ["Mar 2008", 3], ["Apr 2008", 5], ["May 2008", 5], ["Jun 2008", 3], ["Jul 2008", 2], ["Aug 2008", 1]]>> customers_count = [["Mar 2008", 6], ["Apr 2008", 8], ["May 2008", 6], ["Jun 2008", 9]]=> [["Mar 2008", 6], ["Apr 2008", 8], ["May 2008", 6], ["Jun 2008", 9]]>> chart_data = users_count | customers_count=> [["Feb 2008", 1], ["Mar 2008", 3], ["Apr 2008", 5], ["May 2008", 5], ["Jun 2008", 3], ["Jul 2008", 2], ["Aug 2008", 1], ["Mar 2008", 6], ["Apr 2008", 8], ["May 2008", 6], ["Jun 2008", 9]] -Harold On Aug 1, 7:47 am, "David A. Black" <dbl...-0o/XNnkTkwhBDgjK7y7TUQ@public.gmane.org> wrote:> Hi -- > > > > On Fri, 1 Aug 2008, Srinath A. wrote: > > > David A. Black wrote: > >> Hi -- > > >> On Fri, 1 Aug 2008, Ryan Bigg wrote: > > >>>> 5], ["May 2008", 5], ["Jun 2008", 3], ["Jul 2008", 2], ["Aug 2008", > >>>> this type of data is required to pass and display for a fusion chart > >>>> representing 2 different lines with values on chart and month names on > >>>> bottom, i know this would be a strange case....[/b] > > >>>> any help ?? > >>>> thanks > > >>> I think the method you''re looking for is zip. > > >>> @users_count.zip(@customers_count) > > >> No, that doesn''t produce the desired result. > > >> David > > >> -- > >> Rails training from David A. Black and Ruby Power and Light: > >> * Advancing With Rails August 18-21 Edison, NJ > >> * Co-taught by D.A. Black and Erik Kastner > >> Seehttp://www.rubypal.comfor details and updates! > > > Hi David, yep you are right !! > > Great and Thanks a lot for Replying, it works fantastic in my > > application > > and what about if we have third variable say @products_count, can we > > merge this > > too > > Of course. But I shall leave that as an exercise to the reader :-) The > techniques you need should be present in the two-array example. > > David > > -- > Rails training from David A. Black and Ruby Power and Light: > * Advancing With Rails August 18-21 Edison, NJ > * Co-taught by D.A. Black and Erik Kastner > Seehttp://www.rubypal.comfor details and updates!--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
On Fri, Aug 1, 2008 at 6:23 AM, Srinath A. <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> [b]is there any method to merge one array values in to another array, i > mean i have a different situation here. > There are 2 instance variables and generating output like this :[/b] > [code=]@users_count = [["Feb 2008", 1], ["Mar 2008", 3], ["Apr 2008", > 5], ["May 2008", 5], ["Jun 2008", 3], ["Jul 2008", 2], ["Aug 2008", 1]] > @customers_count = [["Mar 2008", 6], ["Apr 2008", 8], ["May 2008", 6], > ["Jun 2008", 9]] > > i want to merge one array in to another to look like : > @chart_data = [["Feb 2008", 1], ["Mar 2008", 3, 6], ["Apr 2008", 5, 8], > ["May 2008", 5, 6], ["Jun 2008", 3, 9], ["Jul 2008", 2], ["Aug 2008", > 1]][/code] > [b] > this type of data is required to pass and display for a fusion chart > representing 2 different lines with values on chart and month names on > bottom, i know this would be a strange case....[/b]Why not use two arrays of hashes? @users_count = [ { :month => "Feb 2008", :count => 1}, { :month => "Mar 2008", :count => 3}, { :month => "Apr 2008", :count => 5}, { :month => "May 2008", :count => 5}, { :month => "Jun 2008", :count => 3}, { :month => "Jul 2008", :count => 2}, { :month => "Aug 2008", :count => 1} ] @customers_count = [ { :month => "Mar 2008", :count => 6}, { :month => "Apr 2008", :count => 8}, { :month => "May 2008", :count => 6}, { :month => "Jun 2008", :count => 9}, ] and perform your merge like this: @chart_data = [] @users_count.each_with_index do |i,hash| @chart_data << [hash[:month],hash[:count],@customers_count[i][:count]] end -- Tim --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---