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

286
Views
Matriz inversa en Javascript sin mutar la matriz original

Array.prototype.reverse invierte el contenido de una matriz en su lugar (con mutación)...

¿Existe una estrategia igualmente simple para invertir una matriz sin alterar el contenido de la matriz original (sin mutación)?

over 4 years ago · Santiago Trujillo
3 answers
Answer question

0

Puede usar slice() para hacer una copia y luego revertirla()

 var newarray = array.slice().reverse(); 

 var array = ['a', 'b', 'c', 'd', 'e']; var newarray = array.slice().reverse(); console.log('a', array); console.log('na', newarray);

over 4 years ago · Santiago Trujillo Report

0

En ES6:

 const newArray = [...array].reverse()
over 4 years ago · Santiago Trujillo Report

0

Otra variante de ES6:

También podemos usar .reduceRight() para crear una matriz invertida sin invertirla.

 let A = ['a', 'b', 'c', 'd', 'e', 'f']; let B = A.reduceRight((a, c) => (a.push(c), a), []); console.log(B);

Recursos útiles:

  • Array.prototype.reduceRight()
  • Arrow Functions
  • Comma Operator
over 4 years ago · Santiago Trujillo 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!