Javascript: Taking the highest 2 numerical values out of a series of 4 possible values.

Posted by Bodhi on Stack Overflow See other posts from Stack Overflow or by Bodhi
Published on 2010-05-03T14:28:46Z Indexed on 2010/05/03 14:38 UTC
Read the original article Hit count: 170

Filed under:

What I'm trying to do is to take the highest two values out of 4 possible variables and add them together, while ignoring the lesser two values. My values will be anywhere between 1 and 5.

So, for example, if I have Trait1, Trait2, Trait3 and Trait4 with the following assigned values: 3, 3, 2, 1, the script will pick up the 3 and the 3, but not the 2 and the 1. If I change the values around so that I have 4, 3, 1, 5, the script will pick up the 4 and the 5, but not the 3 and the 1. How would I go about doing this?

Thank you in advance.

© Stack Overflow or respective owner

Related posts about JavaScript