Last active
December 31, 2017 12:15
-
-
Save egoist/0cf373ba0b83ccc3046fbdeb3d1b6a04 to your computer and use it in GitHub Desktop.
Sort
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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