Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

162
Views
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 answers
Answer question

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 Report

0

if (["good", "beautiful", "pretty", "excellent", "superb", "spectacular"].includes(a)) {...}
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!