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

149
Views
Combinando elementos posteriores de una matriz en Javascript

Tengo una matriz de la siguiente manera:

arr1 = CP-en,AR-es,CP-en,BE-fr,CP-en,CZ-cs

¿Cómo combino los elementos posteriores de la matriz para obtener el siguiente resultado?

resultado = CP-en+AR-es, CP-en+BE-fr, CP-en+CZ-cs

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

0

  1. Necesita dividir su matriz en fragmentos (2 elementos por chank), por ejemplo, indexando así:
 const resultIndex = Math.floor(index / 2)

index aquí es el índice de matriz inicial, resultIndex : nuevo índice del elemento actual (índice de fragmento en realidad).

  1. Únase a ellos como desee usando .join() :
 result.map(chunk => chunk.join('+'))

Código completo:

 const arr = [ 'CP-en', 'AR-es', 'CP-en', 'BE-fr', 'CP-en', 'CZ-cs' ] const result = [] for (let index in arr) { const resultIndex = Math.floor(index / 2) if (!result[resultIndex]) result[resultIndex] = [] result[resultIndex].push(arr[index]) } console.log(result.map(chunk => chunk.join('+')))

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!