QuickSort

Run Settings
LanguageJavaScript
Language Version
Run Command
function quickSort(arr){ if(arr.length<2){ return arr; } let pivot=arr[arr.length-1]; let left=[]; let right=[]; for(let i=0; i<arr.length-1; i++){ if(arr[i]<pivot){ left.push(arr[i]) } else{ right.push(arr[i]); } } return [...quickSort(left),pivot, ...quickSort(right)]; } console.log(quickSort([4,2,76,43,1,-5]))
Editor Settings
Theme
Key bindings
Full width
Lines