function quickSort(arr){ if(arr.length<1){ return arr } var mid=Math.floor(arr.length/2) var temp=arr.splice(mid,1) var left=[] var right=[] for(var i=0;i<arr.length;i++){ if(arr[i]<temp){ left.push(arr[i]) }else if(arr[i]>=temp){ right.push(arr[i]) } } return quickSort(left).concat(temp,quickSort(right)) } var arr=[5,3,9,4,2,0] console.log(quickSort(arr))