This is an implementation of Quick Sort in JS. Can this implantation of Quick Sort be more concise and efficient while still remaining expressive? function quickSort(list){      if( list.length < 2 ) {    return list;     }var leftList = [];var rightList = [];for( var i = 1; i < list.length; i++ ){    if(list[i] >= list[0]){       rightList.push(list[i]) ;    }else{       leftList.push(list[i]);    }}var sortedLeft = quickSort(leftList);var sortedRight = quickSort(rightList);var combined = sortedLeft.concat(list[0]).concat(sortedRight);console.log(combined.join(' '));return combined;}var array=[9,8,7,6,5,4,3,2,1];quickSort(array);Example 2 works with randomly selected pivots, filters, and recursion. This example is more efficient than the first while still remaining as just as expressive. Unfortunately, both perform horribly compared to in place and nonrecursive approaches. function quicksort(arr,len=arr.length) {    if (len <= 1) return arr;        else        var randomIndex = Math.floor(Math.random() * len),        pivot = arr.splice(randomIndex, 1),        lesserHalf = arr.filter(el =>el <= pivot)        biggerHalf = arr.filter((el)=> el > pivot)        return ((lesserHalf, pivot, biggerHalf) =>         [].concat(quicksort(lesserHalf), pivot, quicksort(biggerHalf)))        (lesserHalf, pivot, biggerHalf)}var arr =[9,8,7,6,5,4,3,2,1];console.log(quicksort(arr));Example 3 is the shortest I've seen using spread and inspired by Haskel  const quickSort = ([x = [], ...xs]) => {  if (x.length === 0) return [];  return [    ...quickSort(xs.filter(y => y <= x)),    x,    ...quickSort(xs.filter(y => y > x))  ];}var arr= [9,8,7,6,5,4,3,2,1];console.log(quickSort(arr))
A Concise Quick Sort
javascript;array;quick sort
Before even thinking about performance, concision, etc., run JSLint or similar over these methods and fix the indentation, other whitespace, and bugs. As it is the lack of consistency and poor indentation makes it hard to read and hides things like a missing comma which is leading to implicit semicolon insertion:        var randomIndex = Math.floor(Math.random() * len),        pivot = arr.splice(randomIndex, 1),        lesserHalf = arr.filter(el =>el <= pivot)        biggerHalf = arr.filter((el)=> el > pivot)These four lines also look buggy because pivot is an array and yet it's being compared to an element with <= and >.        var randomIndex = Math.floor(Math.random() * len),            pivot = arr.splice(randomIndex, 1)[0],            lesserHalf = arr.filter(el => el <= pivot),            biggerHalf = arr.filter(el => el > pivot);is more consistent, more obviously correct, and fixes at least one bug.Example 3 also looks buggy.const quickSort = ([x = [], ...xs]) => {  if (x.length === 0) return [];How will this sort [, a, b]? Answer: it will return [].