Javascript Array qs()
// quick sort//ww w . j av a 2 s . c om Array.prototype.qs = function() { var len = this.length; if (len <= 1) { return this.slice(0); } var left = []; var right = []; var mid = [this[0]]; for (var i = 1; i < len; i++) { if (this[i] < mid[0]) { left.push(this[i]); } else { right.push(this[i]); } } return left.qs().concat(mid.concat(right.qs())); }; var arr = [3, 1, 5, 2, 4]; arr = arr.qs();