Skip to content

Instantly share code, notes, and snippets.

@jaunkst
Created June 16, 2020 18:06
Show Gist options
  • Save jaunkst/7179c3ba3c037e9eb330a39b20afa73e to your computer and use it in GitHub Desktop.
Save jaunkst/7179c3ba3c037e9eb330a39b20afa73e to your computer and use it in GitHub Desktop.
quick-sort.js
function quickSort(arr) {
if(arr.length < 2) return arr;
const pivot = arr[0];
const left = [];
const right = [];
for(i=1;i<arr.length;i++){
arr[i] < pivot ? left.push(arr[i]) : right.push(arr[i]);
}
return [...quickSort(left), pivot, ...quickSort(right)]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment