题解 | #快速排序#
快速排序
http://www.nowcoder.com/practice/38da660199d0400580ac3905c05f5bd6
const _quickSort = array => {
// 补全代码
if(Array.isArray(array) && array.length <= 1) return array
let left = []
let right = []
let p = array[array.length-1]
for(let i = 0; i<array.length -1; i++) {
if(array[i] < p) {
left.push(array[i])
} else {
right.push(array[i])
}
}
return [..._quickSort(left), p, ..._quickSort(right)]
}