Accepted v1
var matrixReshape = function(nums, r, c) {
var or = nums.length;
var matrixFull = new Array();
var matrixNew = new Array();
for (var i=0;i<or;i++){
matrixFull = matrixFull.concat(nums[i]);
};
if (r*c != matrixFull.length){
return nums;
} else {
for (var i=0;i<r;i++){
matrixNew[i] = matrixFull.slice(i*c,i*c+c);
}
return matrixNew;
}
};
For Test
var matrixReshape = function(nums, r, c) {
var or = nums.length;
var matrixFull = new Array();
var matrixNew = new Array();
for (var i=0;i<or;i++){
matrixFull = matrixFull.concat(nums[i]);
console.log(matrixFull);
};
if (r*c != matrixFull.length){
return nums;
console.log("WRONG !!!");
} else {
for (var i=0;i<r;i++){
matrixNew[i] = matrixFull.slice(i*c,i*c+c);
console.log(matrixNew[i]);
}
return matrixNew;
}
};
nums = [[1,2],[3,4],[5,6]];
r=6;
c=1;
matrixReshape(nums, r, c);