1/**2* @param {number[][]} matrix3* @return {number[]}4*/5var spiralOrder = function (matrix) {6let [top, bot, left, right, ans] = [70,8matrix.length - 1,90,10matrix[0].length - 1,11[],12];1314while (top <= bot && left <= right) {15for (let j = left; j <= right; j++) {16ans.push(matrix[top][j]);17}18top++;19for (let i = top; i <= bot; i++) {20ans.push(matrix[i][right]);21}22right--;23if (bot < top || right < left) {24break;25}26for (let j = right; left <= j; j--) {27ans.push(matrix[bot][j]);28}29bot--;30for (let i = bot; top <= i; i--) {31ans.push(matrix[i][left]);32}33left++;34}35return ans;36};