export default (matrix) => {
if(matrix.length === 0) return []
let result = []
// 处理每一圈的数据遍历过程
let map = (arr) => {
if(arr.length === 1) {
result = result.concat(arr.shift())
return
}
if(arr.length === 2) {
result = result.concat(arr.shift())
result = result.concat(arr.pop().reverse())
return
}
if(arr.length > 2) {
result = result.concat(arr.shift())
for (let i = 0, n = arr.length; i < n; i++) {
result.push(arr[i].pop())
}
result = result.concat(arr.pop().reverse())
for(let i = arr.length - 1; i >= 0; i--) {
result.push(arr[i].shift())
}
map(arr)
}
}
map(matrix)
result = result.filter(item => item !== undefined)
return result
};