Hi folks, Good day! *I want to find the largest value of given 3 values.* *Please suggest me,the simple ways of finding the largest value.* -- 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 To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/uQKvdH2DJCAJ. For more options, visit https://groups.google.com/groups/opt_out.
Maddy wrote in post #1076411:> Hi folks, > > Good day! > > *I want to find the largest value of given 3 values.* > > *Please suggest me,the simple ways of finding the largest value.*if a,b and c are numbers if(a>b) { if(a>c) {("a is largest")} else {("c is largest")} } else { if(b>c) {("b is largest")} else {("c is largest")} } -- 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 https://groups.google.com/groups/opt_out.
simply put all numbers in array and call max method. a=[2,3,4] a.max On Tue, Sep 18, 2012 at 11:30 AM, Manoj M. <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Maddy wrote in post #1076411: > > Hi folks, > > > > Good day! > > > > *I want to find the largest value of given 3 values.* > > > > *Please suggest me,the simple ways of finding the largest value.* > > if a,b and c are numbers > > if(a>b) > { > if(a>c) > {("a is largest")} > else > {("c is largest")} > } > else > { > if(b>c) > {("b is largest")} > else > {("c is largest")} > } > > -- > 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 https://groups.google.com/groups/opt_out. > > >-- 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 https://groups.google.com/groups/opt_out.
rovin varshney wrote in post #1076418:> simply put all numbers in array and call max method. > > a=[2,3,4] > a.maxyes Rovin ruby way :) -- 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 https://groups.google.com/groups/opt_out.
if we want to get the highest 3 values , then how can we write the code for that .? On Tue, Sep 18, 2012 at 12:34 PM, Manoj M. <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> rovin varshney wrote in post #1076418: > > simply put all numbers in array and call max method. > > > > a=[2,3,4] > > a.max > > yes Rovin ruby way :) > > -- > 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 https://groups.google.com/groups/opt_out. > > >-- 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 https://groups.google.com/groups/opt_out.
roh wrote in post #1076535:> if we want to get the highest 3 values , then how can we write the code > for > that .?data = [10, 20, 70, 60, 40, 30] ordered_data = data.sort_by {|num| -num} p ordered_data p ordered_data[0..2] --output:-- [70, 60, 40, 30, 20, 10] [70, 60, 40] -- 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 https://groups.google.com/groups/opt_out.
On Sep 19, 5:14 am, 7stud -- <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> roh wrote in post #1076535: > > > if we want to get the highest 3 values , then how can we write the code > > for > > that .? > > data = [10, 20, 70, 60, 40, 30] > ordered_data = data.sort_by {|num| -num} > > p ordered_data > p ordered_data[0..2]Or data.sort.last(3) I think you might need ruby 1.9 to be able to pass an argument to last like that. Fred> > --output:-- > [70, 60, 40, 30, 20, 10] > [70, 60, 40] > > -- > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.