1let matrix = [
2 [0,0,0,0,0],
3 [0,0,0,0,0],
4 [0,0,0,0,0],
5 [0,0,0,0,0],
6]
7// copies just values, not references!
8function getCopyOfMatrix(mat) {
9 return mat.map(row => row.map(col => col))
10}
11
12let copyOfMatrix = getCopyOfMatrix(matrix);
1let matrix = [
2 [0,0,0,0,0],
3 [0,0,0,0,0],
4 [0,0,0,0,0],
5 [0,0,0,0,0],
6]
7// copies just values, not references!
8function getCopyOfMatrix(mat) {
9 return JSON.parse(JSON.stringify(mat))
10}
11
12let copyOfMatrix = getCopyOfMatrix(matrix);