// [1, 2, 3]
// [4, 5, 6]
// [7, 8, 9]
// [10,11,12]
//
// print order 1, 2, 4, 3, 5, 7, 6, 8, 10, 9, 11, 12
function test() {
let arr = [
[1, 2, 3],
[4, 5, 6],
[7, 8, 9],
[10, 11, 12]];
let sum = arr.length + arr[0].length - 2;
let j0 = 0, i,j
for(let index = 0; index <= sum; index ++) {
if(j0 === arr[0].length) {
j0 --
}
j = j0
i = index - j0
while(j >= 0 && i <= index && i < arr.length && j < arr[0].length) {
console.log(arr[i][j]);
i ++;
j = index - i;
}
j0 ++
}
}
test()
标签:11,10,arr,12,index,打印,矩阵,算法,let From: https://www.cnblogs.com/zjy4fun/p/17486622.html