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

135
Visualizações
Statement for specific truth table

I have three variables, variation, attribute and active for which I need to create an if statement for the following truth table:

variation attribute active Result
[object Object] 'color' true TRUE
undefined undefined undefined TRUE
[object Object] 'color' false FALSE

But I can't think of a smart and compact statement for the case, unless I write all desired true scenarios in an or separated long statement...

Can someone please help me with this?

Here is a quick fiddle for you.

TIA.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You can negate all the values to booleans and check if they are all equal:

!variation == !attribute && !attribute == !active

Values in JavaScript can be either truthy or falsy.

  • [object Object], 'color', true => truthy
  • undefined, false => falsy

So when you put the logical NOT operator (!) before a value, you effectively negate it, meaning all truthy values become the boolean false and all falsy values are cast to the boolean true.


Your truth table seems to return true when all of the variables are truthy or when all of the variables are falsy, and returns false when they are mixed.

So it essentially checks that all the values, when casted to booleans, are equal. So the condition above casts the values to opposite booleans and checks that they are all the same.

about 4 years ago · Juan Pablo Isaza Relatório
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