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

195
Views
Agregar texto " / ", "o" y "y" después de unir las matrices

Tengo una matriz de matrices anidadas y necesito unirlas usando el texto "/", "o" y "y".

Si está dentro de la misma matriz, entonces se unirá con " y ".

Si es hermano, entonces se une con "o".

De lo contrario, únete con "\".

Ejemplo 1:-

La salida debe ser:

ARTH 332 / HIST 364 y HIST 365

 [ [ [ "ARTH 332" ] ] [ [ "HIST 364" "HIST 365" ] ] ]

Ejemplo 2:-

La salida debe ser:

BUS 300 / BUS 310 / BUS 330 / MKT 300 / ACCT 301 / MGMT 362 / BUS 345 o BUS 340

 [ [ [ "BUS 300" ] ] [ [ "BUS 310" ] ] [ [ "BUS 330" ] ] [ [ "MKT 300" ] ] [ [ "ACCT 301" ] ] [ [ "MGMT 362" ] ] [ [ "BUS 345" ] [ "BUS 340" ] ] ]
about 4 years ago · Santiago Gelvez
1 answers
Answer question

0

Simplemente itere sobre la matriz y diferencie entre los tres casos para and , or y nothing . Finalmente únase al resultado en / . También agregué , para hacer que los datos proporcionados sean una matriz válida.

 let y = [ [ ["ARTH 332"] ], [ ["HIST 364", "HIST 365"] ] ] let x = [ [ ["BUS 300"] ], [ ["BUS 310"] ], [ ["BUS 330"] ], [ ["MKT 300"] ], [ ["ACCT 301"] ], [ ["MGMT 362"] ], [ ["BUS 345"], ["BUS 340"] ] ]; let z = [ [ ["BUS 300"] ], [ ["BUS 310"] ], [ ["BUS 330"] ], [ ["MKT 300"] ], [ ["ACCT 301"] ], [ ["MGMT 362"] ], [ ["BUS 345"], ["BUS 340","BUS 340"] ] ] function transform(a) { let length = a.length; let result = []; for (let i = 0; i < length; i++) { if (a[i].length > 1) { result.push( a[i].map(e=>e.join(" and ")).join(" or ") ) } else if (a[i][0].length > 1) { result.push(a[i][0].join(" and ")) } else { result.push(a[i][0]); } } return result.join(" / "); } console.log(transform(y)); console.log(transform(x)); console.log(transform(z));

about 4 years ago · Santiago Gelvez 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!