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

167
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

0

if (["good", "beautiful", "pretty", "excellent", "superb", "spectacular"].includes(a)) {...}
about 4 years ago · Juan Pablo Isaza Denunciar
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