let matrix = [
[0,0,0,0,0],
[0,0,0,0,0],
[0,0,0,0,0],
[0,0,0,0,0],
]
// copies just values, not references!
function getCopyOfMatrix(mat) {
return mat.map(row => row.map(col => col))
}
let copyOfMatrix = getCopyOfMatrix(matrix);
let matrix = [
[0,0,0,0,0],
[0,0,0,0,0],
[0,0,0,0,0],
[0,0,0,0,0],
]
// copies just values, not references!
function getCopyOfMatrix(mat) {
return JSON.parse(JSON.stringify(mat))
}
let copyOfMatrix = getCopyOfMatrix(matrix);
function copy2DArray(array) {
return array.map(row => [...row]);
}