Skip to content

Instantly share code, notes, and snippets.

@unbug unbug/quicksort
Created May 21, 2016

What would you like to do?
function quicksort(arr){
//base case
if(arr.length<=1){ return arr;}
//now find swap position and value
var swapPos = Math.floor((arr.length-1)/2),
swapVal = arr[swapPos],
less = [], more = [];
arr = arr.slice(0, swapPos).concat(arr.slice(swapPos+1));
for(var i=0;i<arr.length;i++){
if(arr[i]< swapVal){
return (quicksort(less)).concat([swapVal], quicksort(more));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.