Array.prototype.quickSort = function() {
var len = this.length;
if(len < 2) return this;
var left = [], right = [], base = this[0];
for(var i = 1; i < len; i ++) {
var iv = this[i];
iv >= base && right.push(iv);
iv < base && left.push(iv);
}
return left.quickSort().concat(base, right.quickSort())
} var arr = [5, 3, 7, 4, 1, 9, 8, 6, 2];
console.log(arr.quickSort())

抄wiki的,代码质量高,实现简单

https://zh.wikipedia.org/wiki/%E5%BF%AB%E9%80%9F%E6%8E%92%E5%BA%8F#JavaScript

05-14 22:26