SOURCE

function quickSort(arr, left, right) {
  let len = arr.length, partitionIndex;
  left = typeof left !== 'number' ? 0 : left;
  right = typeof right !== 'number' ? len - 1 : right;
  if(left < right) {
    partitionIndex = partition(arr, left, right);
    quickSort(arr, left, partitionIndex - 1);
    quickSort(arr, partitionIndex + 1, right);
  }
  return arr;
}

function partition(arr, left, right) {
  let pivot = left, index = pivot + 1;
  for(let i = index; i <= right; i++) {
    if(arr[i] < arr[pivot]) {
      swap(arr, i, index);
      index++;
    }
  }
  swap(arr, pivot, index - 1);
  return index - 1;
}

function swap(arr, first, second) {
  let temp = arr[first];
  arr[first] = arr[second];
  arr[second] = temp;
}

var arr = [23, 9, 12, 5, 8, 3, 2, 30];

console.log(quickSort(arr));
console 命令行工具 X clear

                    
>
console