var arr = [3, 1, 4, 6, 5, 7, 2]; // Array.prototype.sort console.log(arr.sort((a,b) => a - b)) // 快排 function quickSort(arr) { if (!arr.length) { return []; } const index = Math.floor(arr.length / 2); const current = arr.splice(index, 1); const left = []; const right = []; for (let i = 0; i < arr.length; i++) { if (arr[i] <= current) { left.push(arr[i]); } else { right.push(arr[i]); } } return quickSort(left).concat(current, quickSort(right)); } console.log(quickSort(arr));