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

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

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]

On Sep 19, 5:14am, 7stud – [email protected] 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

if we want to get the highest 3 values , then how can we write the code

for

that .?

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