hi guys
1- my question is why we need to reinitialize the raw variable inside the for Loop if it is declared before?
2- and why the row.push(0) push more than one 0 (six zeros before) without using iteration like I or j?
3- because if you want to push two zeros you can do it that way row.push(0) * j
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
row = [];
for (let j = 0; j < n; j++) {
// Pushes n zeroes into the current row to create the columns
row.push(0);
}
// 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);