Recommended Posts

Is there a way to easily find the second highest or third highest value in an array?  I know I can use Max/Min, but not sure if I wanted to find the two highest values how to find the next easily?

Share this post


Link to post
Share on other sites

Well, there isn't a built in function for this like min2() or min(val, 2) or something, but it is not hard to do using boolean math, especially if all the values are > 0.  You'd basically have to iterate through, removing values as you go using boolean math:

private themax = max(myArray)
private themax2 = max(myArray * (myArray < themax))
private themax3 = max(myArray * (myArray < theMax2))

etc...

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now