loading
open in
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
function zeroArray(m, n) {
  // Creates a 2-D array with m rows and n columns of zeroes
  let newArray = [];
 
  for (let i = 0; i < m; i++) {
    // Adds the m-th row into newArray
     let 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;
}
var arrayInsideZeroArray;
let matrix = zeroArray(3, 2);
console.log(matrix);
node v10.15.2 linux/amd64