I'm learning Javascript and I'm trying to build a website with a tool for musicians. Here's something I can't figure out how to achieve using normal conditions, comparisons, etc.
Let's say I have 5 variables:
a = 0;
b = 0;
c = 0;
d = 0;
e = 0;
Now using some checkboxes, the variables now update to:
a = 0;
b = 3;
c = 1;
d = 3;
e = 0;
So I want variables b and d to become the prioritized variables, because they are both the variables with the highest value (3). Or if only 1 variable would get the highest value, that single variable would be priority, for example:
a = 0;
b = 7;
c = 1;
d = 3;
e = 0;
In this case variable b would become prioritized, because it's the highest number.
What's the best way to accomplish this? Basically I want to compare all values and first check what's the highest value? Then, the variable or variables with that value would be assigned for example a different name or value. For example if each variable was a musical note name (C, D#, F, G, Ab), then I would add a + sign to their name (e.g. D#+ and G+). This part, what the end result will be on the front end, is not that relevant, to be honest. I just want to understand what kind of logic goes behind this and how can that be achieved?
Thank you! :)
EDIT: So one approach I was thinking of was: First, gather all the variables and sort them from highest value to lowest:
b = 3;
d = 3;
c = 1;
a = 0;
e = 0;
First, set b to TRUE. Then compare d with b. If it's the same number, set it to TRUE, else set it to FALSE. Do the same for c and compare it to B. Compare a with b, e with B.
I end up with all the TRUE variables at the top and all the other ones as FALSE.
Is this a good approach? Is there another easier alternative? This works with 5 variables, but what about if I had 100?