//m*n的二维数组,顺时针打印
// []
const m = 5;
const n = 6;
let arr = []
for(let i = 0; i < m; i++){
arr[i] = [];
for(let j = 0; j < n; j++){
arr[i][j] = '' + i + j
}
console.log(arr[i])
}
let row = [0, m-1];
let col = [0, n-1];
let direction = 'right';
function print(row, col){
if(row[0] > row[1] || col[0] > col[1]) {
return
};
if(direction === 'right'){
for(let j = col[0]; j <= col[1]; j++){
console.log(arr[row[0]][j]);
}
direction = 'down';
row[0]++;
}else if(direction === 'down'){
for(let j = row[0]; j <= row[1]; j++){
console.log(arr[j][col[1]]);
}
direction = 'left';
col[1]--;
}else if(direction === 'left'){
for(let j = col[1]; j >= col[0]; j--){
console.log(arr[row[1]][j]);
}
direction = 'up';
row[1]--;
}else if(direction === 'up'){
for(let j = row[1]; j >= row[0]; j--){
console.log(arr[j][col[0]]);
}
direction = 'right';
col[0]++;
}
print(row, col);
}
print(row, col)