// 牌底 => 牌顶 // [] [5, 4, 3, 2, 1] // [1] [2, 5, 4, 3] // [3, 1] [4, 2, 5] // [5, 3, 1] [2, 4] // [4, 5, 3, 1] [2] // [2, 4, 5, 3, 1] const fn = (arr) => { let res = [] while(arr.length){ const item = arr.shift() if(res.length >= 2){ const first = res.shift() res.push(first) } res.push(item) console.log(res) } return res } console.log(fn([2, 4, 5, 3, 1]))