Recommended Posts

Posted

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?

Posted

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

 

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.