[Rails] Re: Re: Re: Find the largest value of given 3 values
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@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home