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

163
Visualizações
Could I simplify the following javascript logical OR code?

I have a code in my project but it is kind of clunky. Could anyone help me to simplify the following code?

if (a == "good" || a == "beautiful || a == "pretty"|| a == "excellent" || a == "superb"|| a == "spectacular")

Could I make this into some sort of array and then use that array in this if code?

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

0

I suppose you could use a Hash-Set structure instead: in JS this is Set (or Set<T> in TypeScript):

const positiveWords = new Set( [ "good", "beautiful", "pretty", "excellent", "superb", "spectacular" ] );

Usage:

if( positiveWords.has( a ) ) {
    
}

Note that you'll need to convert a to lowercase first. If you want case-insensitive (or accent-insensitive, or other culture/locale-specific comparison rules) then use Intl and/or localeCompare.

about 4 years ago · Juan Pablo Isaza Relatório

0

if (["good", "beautiful", "pretty", "excellent", "superb", "spectacular"].includes(a)) {...}
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