function quickSort(arr, start, end) {
if (start >= end) return;
var pivotIndex = end;
var pivotValue = arr[end];
var tmpStart = start
var tmpEnd = end
while (true) {
for (; start < end; start++) {
if (arr[start] >= pivotValue) {
break;
}
}
for (; end > start; end--) {
if (arr[end] < pivotValue) {
break;
}
}
if (start == end) {
[arr[start], arr[pivotIndex]] = [arr[pivotIndex], arr[start]]
break
}
[arr[start], arr[end]] = [arr[end], arr[start]]
}
quickSort(arr, tmpStart, end - 1)
quickSort(arr, end + 1, tmpEnd)
}
arr = [3, 5, 2, 1, 8]
quickSort(arr, 0, 4) // 从 5 开始 到8结束
console.log(111, arr)