var arr = [
[1, 2, 3],
[4, 5, 6],
[7, 8, 7]
]
function print(arr) {
let res = []
let max = (arr.length - 1) * 2
for (let i = 0; i <= max; i++) {
let x = 0, y = i
for (; y >= 0; x++, y--) {
if (x < arr.length && y < arr.length) {
res.push(arr[x][y])
}
}
}
return res
}
console.log(print(arr));
//[1, 2, 4, 3, 5, 7, 6, 8, 7]
45°打印矩阵
于 2022-04-29 11:49:26 首次发布