Originally Posted by Airblader
For once I'll post dirt, ugly code – which will save you the if/else statements:
var max = Math.max(a,b,c);
var cnt = 1*(a==max)+1*(b==max)+1*(c==max);
But keep in mind that readability is considered important these days, especially if you ever consider doing this as a job. So you might be better of using something readable and extensible, i.e. using a forEach function on [a, b, c].
That says how many variables have (share) the hightest value, but not which ones they are. It is not much use to be told that one of the numbers (unspecified) is the highest. We sort of knew that!
All the code given in this post has been tested and is intended to address the question asked.
Unless stated otherwise it is not just a demonstration.
Last edited by Philip M; 03-13-2013 at 10:55 PM..