Created
February 8, 2018 09:32
-
-
Save dondevi/9862e66cefc7766f618437e3cd65b669 to your computer and use it in GitHub Desktop.
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
/** | |
* 快速排序 | |
* @param {Array} array - 乱序数组 | |
*/ | |
function quickSort (array) { | |
if (0 === array.length) { return array; } | |
let key = array.shift(); | |
let lessers = []; | |
let greaters = []; | |
for (let i = 0, item = null; item = array[i]; i++) { | |
item < key ? lessers.push(item) : greaters.push(item); | |
} | |
return [...quickSort(lessers), key, ...quickSort(greaters)]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment