Skip to content

Instantly share code, notes, and snippets.

@youngdo212
Created July 20, 2018 05:02
Show Gist options
  • Save youngdo212/27d156349f382ff461da5281c390f67a to your computer and use it in GitHub Desktop.
Save youngdo212/27d156349f382ff461da5281c390f67a to your computer and use it in GitHub Desktop.
function quickSort(arr){
if(arr.length === 0) return arr;
let pivot = arr.pop();
let i = -1;
for(j = 0; j < arr.length; j++){
if(arr[j] <= pivot){
i++;
[arr[i], arr[j]] = [arr[j], arr[i]];
}
}
return [...quickSort(arr.slice(0, i+1)), pivot, ...quickSort(arr.slice(i+1))];
}
console.log(quickSort([10,80,30,90,40,50,70]));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment