The following code is to rotate a mxn size array to -90 degree.
function rotateN90(a){
var temp = new Array(a[0].length); // number of columns
var i=0;
for (i = 0; i < temp.length; i++) {
temp[i] = [];
}
for(i=0;i<a.length;i++){
for(let j = 0; j<a[0].length;j++){
temp[j][i]= a[i][a[i].length-1-j];
}
}
return temp;
}
If your array is :
[[1, 2,3],[4, 5, 6]]
It will rotate -90 degree and returned array will be
[[3, 6],[2, 5],[1, 4]]
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…