Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

96
Vistas
Checking values in variables and show one or more of the highest ones

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?

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda