Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

102
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda