1. const quickSort = (array) => {
    2. const length = array.length
    3. if (length <= 1) {
    4. return array
    5. }
    6. const midIndex = Math.floor(length / 2)
    7. const midValue = array.splice(midIndex, 1)[ 0 ]
    8. let leftArray = []
    9. let rightArray = []
    10. let index = 0
    11. while (index < length - 1) {
    12. const curValue = array[ index ]
    13. if (curValue <= midValue) {
    14. leftArray.push(curValue)
    15. } else {
    16. rightArray.push(curValue)
    17. }
    18. index++
    19. }
    20. return quickSort(leftArray).concat([ midValue ], quickSort(rightArray))
    21. }
    22. const arr = [ -10, 10, 1, 34, 5, 1 ]
    23. console.log(quickSort(arr)) // [-10, 1, 1, 5, 10, 34]