# Array of integers

**URL:** <https://www.ruby-forum.com/t/array-of-integers/74156>\
**Category:** Ruby\
**Created:** [October 31, 2006, 2:15pm UTC](https://www.ruby-forum.com/t/array-of-integers/74156 "2006-10-31T14:15:32Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![brad7a0](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/53a042/32.png) [@brad7a0](https://www.ruby-forum.com/u/brad7a0)\
**Post date:** [October 31, 2006, 2:15pm UTC](https://www.ruby-forum.com/t/array-of-integers/74156/1 "2006-10-31T14:15:32Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![brad7a0](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/53a042/32.png) [@brad7a0](https://www.ruby-forum.com/u/brad7a0)\
**Post date:** [October 31, 2006, 3:12pm UTC](https://www.ruby-forum.com/t/array-of-integers/74156/2 "2006-10-31T15:12:29Z")

</div>

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).

---

<div class="post-metadata">

**Author:** ![brad7a0](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/53a042/32.png) [@brad7a0](https://www.ruby-forum.com/u/brad7a0)\
**Post date:** [November 7, 2006, 10:48am UTC](https://www.ruby-forum.com/t/array-of-integers/74156/3 "2006-11-07T10:48:54Z")

</div>

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 = 4
> 
> How is this done in Ruby?

[n6tadam@workstation fvwm]% irb

> > [1,2,3].max  
> > =\> 3
> 
> > [1,2,3].min  
> > =\> 1

– Thomas A.
