A Concise Quick Sort 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 &lt; 2 ) {
    return list;     
}
var leftList = [];
var rightList = [];
for( var i = 1; i &lt; list.length; i++ ){
    if(list[i] &gt;= 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 &lt;= 1) return arr;
        else
        var randomIndex = Math.floor(Math.random() * len),
        pivot = arr.splice(randomIndex, 1),
        lesserHalf = arr.filter(el =&gt;el &lt;= pivot)
        biggerHalf = arr.filter((el)=&gt; el &gt; pivot)
        return ((lesserHalf, pivot, biggerHalf) =&gt; 
        [].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]) =&gt; {
  if (x.length === 0) return [];
  return [
    ...quickSort(xs.filter(y =&gt; y &lt;= x)),
    x,
    ...quickSort(xs.filter(y =&gt; y &gt; x))
  ];
}

var arr= [9,8,7,6,5,4,3,2,1];

console.log(quickSort(arr))
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 =&gt;el &lt;= pivot)
        biggerHalf = arr.filter((el)=&gt; el &gt; pivot)



These four lines also look buggy because pivot is an array and yet it's being compared to an element with &lt;= and &gt;.

        var randomIndex = Math.floor(Math.random() * len),
            pivot = arr.splice(randomIndex, 1)[0],
            lesserHalf = arr.filter(el =&gt; el &lt;= pivot),
            biggerHalf = arr.filter(el =&gt; el &gt; pivot);


is more consistent, more obviously correct, and fixes at least one bug.



Example 3 also looks buggy.


const quickSort = ([x = [], ...xs]) =&gt; {
  if (x.length === 0) return [];



How will this sort ["", "a", "b"]? Answer: it will return [].