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

92
Views
No se puede copiar matriz 2D en JavaSctipt

Mi función acepta una matriz 2D, luego quiero copiarla, pero obtengo una matriz 2D vacía en su lugar:

 function getGeneration(cells, generations){ let cellsOfGen= []; for (let i = 0; i < cells.length; i++) { console.log(cells[i]) // normal output - [1,0,0], then [0,1,1], then [1,1,0] cellsOfGen.push(cells[i]) // pushes empty array } console.log(cellsOfGen) // result - [ [], [], [] ] } let cells = [[1,0,0],[0,1,1],[1,1,0]] console.log(getGeneration(cells, 1))

También intenté empujar cada elemento en matrices anidadas, y funcionó:

 function getGeneration(cells, generations){ let cellsOfGen= []; for (let i = 0; i < cells.length; i++) { console.log(cells[i]) // normal output - [1,0,0], then [0,1,1], then [1,1,0] cellsOfGen.push(...cells[i]) } console.log(cellsOfGen) // result - [ 1, 0, 0, 0, 1, 1, 1, 1, 0 ] } let cells = [[1,0,0],[0,1,1],[1,1,0]] console.log(getGeneration(cells, 1))

No entiendo lo que está pasando, ayúdame si sabes algo por favor.

about 4 years ago · Juan Pablo Isaza
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!