# Find the largest value of given 3 values

**URL:** <https://www.ruby-forum.com/t/find-the-largest-value-of-given-3-values/222986>\
**Category:** Rails\
**Created:** [September 18, 2012, 7:48am UTC](https://www.ruby-forum.com/t/find-the-largest-value-of-given-3-values/222986 "2012-09-18T07:48:09Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![aris](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/258eb7/32.png) [@aris](https://www.ruby-forum.com/u/aris)\
**Post date:** [September 18, 2012, 7:48am UTC](https://www.ruby-forum.com/t/find-the-largest-value-of-given-3-values/222986/1 "2012-09-18T07:48:09Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [September 18, 2012, 8:00am UTC](https://www.ruby-forum.com/t/find-the-largest-value-of-given-3-values/222986/2 "2012-09-18T08:00:42Z")

</div>

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”)}  
}

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [September 18, 2012, 8:41am UTC](https://www.ruby-forum.com/t/find-the-largest-value-of-given-3-values/222986/3 "2012-09-18T08:41:55Z")

</div>

simply put all numbers in array and call max method.

a=[2,3,4]  
a.max

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [September 18, 2012, 9:04am UTC](https://www.ruby-forum.com/t/find-the-largest-value-of-given-3-values/222986/4 "2012-09-18T09:04:00Z")

</div>

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 🙂

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [September 19, 2012, 6:13am UTC](https://www.ruby-forum.com/t/find-the-largest-value-of-given-3-values/222986/5 "2012-09-19T06:13:31Z")

</div>

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]

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [September 19, 2012, 9:29am UTC](https://www.ruby-forum.com/t/find-the-largest-value-of-given-3-values/222986/6 "2012-09-19T09:29:07Z")

</div>

On Sep 19, 5:14am, 7stud – [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> 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

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [September 18, 2012, 11:15pm UTC](https://www.ruby-forum.com/t/find-the-largest-value-of-given-3-values/222986/7 "2012-09-18T23:15:37Z")

</div>

if we want to get the highest 3 values , then how can we write the code  
for  
that .?
