Find the largest value of given 3 values

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.

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

simply put all numbers in array and call max method.

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

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 :slight_smile:

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

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]

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