I have a Matrix contained in a 2D-array:
var testM = [
[0.0,2.0,3.0],
[1.0,1.0,1.0],
[7.0,5.0,6.0]
];
// swap row a with b
function swapRows(a,b){
let temp = a.slice(); // Copy by value, not reference
a = b.slice();
b = temp;
}
// The individual arrays are passed in:
swapRows(testM[0], testM[1]);
However, the original 2D array remains unchanged after running the above code. I'm not too familiar with passing by reference in javascript, so any help is appreciated. (Note: it works fine when pasted inline, just wondering why it doesn't function even when copied by value)
EDIT: I completely understand how to swap the elements of a regular, one-dimensional array; I was inquiring more about about the mechanics of passing by reference in javascript. (I don't even know if I'm using the right terminology)