Quick Sort

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