![](https://img2018.cnblogs.com/blog/1853166/202001/1853166-20200127150544826-1977734878.png) ![](https://img2018.cnblogs.com/blog/1853166/202001/1853... ...
export default (arr) => {
// 處理每一圈的數據遍歷過程
let map = (arr, r = []) => {
for (let i = 0, len = arr.length; i < len; i++) {
if (i === 0) {
r = r.concat(arr[i])
} else if (i === len - 1) {
r = r.concat(arr[i].reverse())
} else {
r.push(arr[i].pop())
}
}
arr.shift()
arr.pop()
for (let i = arr.length - 1; i >= 0; i--) {
r.push(arr[i].shift())
}
if (arr.length) {
return map(arr, r)
} else {
return r
}
}
return map(arr, [])
}