I''ve got a form that has several checkboxes on it with labels and values of A - E. I want to display the most commonly selected values. I also need to consider the possibility that a user may select equal numbers of each value. What would be the best COA for displaying the results of this form? -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Pale Horse wrote:> I''ve got a form that has several checkboxes on it with labels and values > of A - E. I want to display the most commonly selected values. > > I also need to consider the possibility that a user may select equal > numbers of each value. > > What would be the best COA for displaying the results of this form?Put the values into an array or the DB, run calculations, display the results. Which part are you having trouble with? Best, -- Marnen Laibow-Koser http://www.marnen.org marnen-sbuyVjPbboAdnm+yROfE0A@public.gmane.org -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@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.
Marnen Laibow-Koser wrote:> Pale Horse wrote: >> I''ve got a form that has several checkboxes on it with labels and values >> of A - E. I want to display the most commonly selected values. >> >> I also need to consider the possibility that a user may select equal >> numbers of each value. >> >> What would be the best COA for displaying the results of this form? > > Put the values into an array or the DB, run calculations, display the > results. Which part are you having trouble with?I''ve got the values into an array. How, then, do I count the number of, for example, C values? I thought there would be an array method to determine the most commonly occurring values and return them.> > Best, > -- > Marnen Laibow-Koser > http://www.marnen.org > marnen-sbuyVjPbboAdnm+yROfE0A@public.gmane.org-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@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 22 September 2010 14:49, Pale Horse <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Marnen Laibow-Koser wrote: >> Pale Horse wrote: >>> I''ve got a form that has several checkboxes on it with labels and values >>> of A - E. I want to display the most commonly selected values. >>> >>> I also need to consider the possibility that a user may select equal >>> numbers of each value. >>> >>> What would be the best COA for displaying the results of this form? >> >> Put the values into an array or the DB, run calculations, display the >> results. Which part are you having trouble with? > > I''ve got the values into an array. How, then, do I count the number of, > for example, C values? I thought there would be an array method to > determine the most commonly occurring values and return them.One way would be something like num = array.select { |v| v== ''C'' }.length I expect there are better ways. Colin -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@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.
Colin Law wrote:> On 22 September 2010 14:49, Pale Horse <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote: >>> Put the values into an array or the DB, run calculations, display the >>> results. �Which part are you having trouble with? >> >> I''ve got the values into an array. How, then, do I count the number of, >> for example, C values? I thought there would be an array method to >> determine the most commonly occurring values and return them. > > One way would be something like > num = array.select { |v| v== ''C'' }.lengthI, too, expected there to be a better way. I did forget about the select method but just read and tried it prior to reading your post. Thanks for your help, regardless.> > I expect there are better ways. > > Colin-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@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.
Pale Horse wrote:> Marnen Laibow-Koser wrote: >> Pale Horse wrote: >>> I''ve got a form that has several checkboxes on it with labels and values >>> of A - E. I want to display the most commonly selected values. >>> >>> I also need to consider the possibility that a user may select equal >>> numbers of each value. >>> >>> What would be the best COA for displaying the results of this form? >> >> Put the values into an array or the DB, run calculations, display the >> results. Which part are you having trouble with? > > I''ve got the values into an array. How, then, do I count the number of, > for example, C values? I thought there would be an array method to > determine the most commonly occurring values and return them. >Enumerable#count and #group_by will probably be helpful here. Best, -- Marnen Laibow-Koser http://www.marnen.org marnen-sbuyVjPbboAdnm+yROfE0A@public.gmane.org -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@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.