Consider a matrix B= [[6,4,1,2], [5,3,9,7],[1,3,2,1]];
. B is a matrix with three rows and four columns. I want to treat it as an array or a vector, namely B1=[6,4,1,2,5,3,9,7,1,3,2,1]
. Moreover, I want to have, for instance, that B1[3]=2
- so it's a number, not a vector anymore. I wrote a simple function
function NewArray(Matrix){
var Temp = [];
var w = Matrix[0].length;
var h = Matrix.length;
for (i=0; i<w; i++){
for (j=0; j<h; j++){
Temp.push(Matrix[i][j]);
}
}
return Temp;
}
It occours haowever, that it works only, when B is quadratic. What is wrong?