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

157
Views
Reiniciar variable dentro de un bucle. Ayúdame a entender su impacto en el siguiente código

 function zeroArray(m, n) { // Creates a 2-D array with m rows and n columns of zeroes let newArray = []; let row = []; for (let i = 0; i < m; i++) { // Adds the m-th row into newArray for (let j = 0; j < n; j++) { // Pushes n zeroes into the current row to create the columns row.push(0); console.log(row); } // Pushes the current row, which now has n zeroes in it, to the array newArray.push(row); } return newArray; } let matrix = zeroArray(3, 2); console.log(matrix);

En este código, debo reinicializar la variable de fila en el bucle externo en una matriz vacía para crear una matriz 2D con filas y columnas que se vean así: [[0,0], [0,0], [0, 0]]. Sin reiniciar la variable, obtengo un resultado completamente diferente. Entiendo cómo funciona el código, pero no entiendo el impacto total de la reinicialización. ¿Por qué establecer la variable de fila nuevamente en una matriz vacía crearía una salida diferente?

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!