Skip to content

Instantly share code, notes, and snippets.

@egoist
Last active December 31, 2017 12:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save egoist/0cf373ba0b83ccc3046fbdeb3d1b6a04 to your computer and use it in GitHub Desktop.
Save egoist/0cf373ba0b83ccc3046fbdeb3d1b6a04 to your computer and use it in GitHub Desktop.
Sort
function quickSort(list) {
if (list.length < 2) {
return list
}
const candidate = list[list.length - 1]
const less = list.filter(i => i < candidate)
const greater = list.filter(i => i > candidate)
return [
...quickSort(less),
candidate,
...quickSort(greater)
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment