function quick(arr) { if(arr.length<=1){ return arr } let a = Math.round(arr.length/2) let piv = arr[a] let left = arr.filter(x => x < piv) let mids = arr.filter(x => x == piv) let right = arr.filter(x => x > piv) // return quick(left).concat(mids, quick(right)) return [...quick(left), ...mids, ...quick(right)] } console.log(quick([3,5,1,3,4,5,6,7,8,8,5,9,8,3]))