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

546
Views
Create function to convert given string

Create function to convert given string to the output below

// Input
const optionRule = '{1069} AND ({1070} OR {1071} OR {1072}) AND {1244} AND ({1245} OR {1339})';

// Output Example
/* const output = {
  and: [
    1069,
    { or: [1070, 1071, 1072] },
    1244,
    { or: [1245, 1339] },
  ]
}; */

let result = 'result'

console.log('result:', result);

Can anyone help me solve this?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Please don't just ask help for the solution. Try to solve it yourself and put some code in the question. Since, this community is for helping. I will give you a simple solution.

const fnconvertString = (str) => {
    const strArr = str.split(' AND ')
    const output = strArr.map(item => {
    let temp = item.split(' OR ')
    if (temp.length < 2) {
            return Number(temp[0].replace(/[{()}]/g, ''))
    } else {
        let temp1 = temp.map(i => Number(i.replace(/[{()}]/g, '')))
      return {
        'or': temp1
      }
    }
  })
  return output
}
console.log( fnconvertString(optionRule))
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!