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

244
Views
How to attach multiple class method from loop?

.regularExpression() is hardcoded 3 times in the script, is there a way to dynamically attach it from loops from variable const regex = ['reg1', 'reg2', 'reg3']?

Usage:

{
       text: Check.string()
                  .regularExpression(/reg1/)
                  .regularExpression(/reg2/)
                  .regularExpression(/reg3/)
}
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You can use the reduce method:

const regex = ['reg1', 'reg2', 'reg3'];
{
  text: regex.reduce((check, regex) => check.regularExpression(new RegExp(regex)), Check.string())
}

In this way, starting from the initial value Check.string(), you will iteratively chain new regular expressions, accordingly to your array.

Alternatively, you can use a plain for-loop:

let check = Check.string();
for (const item of regex) {
  check = check.regularExpression(new RegExp(regex));
}

{
  text: check
}
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!