What is the best way to get determine the largest and smallest int in an
array of ints? For example:
x = [1,2,3,4]
x.smallest should = 1
x.largest should = 4
How is this done in Ruby?
Thank you,
Brad
What is the best way to get determine the largest and smallest int in an
array of ints? For example:
x = [1,2,3,4]
x.smallest should = 1
x.largest should = 4
How is this done in Ruby?
Thank you,
Brad
Brad T. wrote:
What is the best way to get determine the largest and smallest int in an
array of ints? For example:x = [1,2,3,4]
puts x.max
puts x.min
See the documentation for Enumerable (try “ri Enumerable” at your
prompt).
On Tue, Oct 31, 2006 at 10:15:35PM +0900, Brad T. wrote:
What is the best way to get determine the largest and smallest int in an
array of ints? For example:x = [1,2,3,4]
x.smallest should = 1
x.largest should = 4How is this done in Ruby?
[[email protected] fvwm]% irb
[1,2,3].max
=> 3[1,2,3].min
=> 1
– Thomas A.
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.
Sponsor our Newsletter | Privacy Policy | Terms of Service | Remote Ruby Jobs