Here you can find the source of quickSort()
Array.prototype.quickSort = function () { if (this.length <= 1) { return this; }/*from ww w .j a v a 2 s . c om*/ var pointIndex = Math.floor(this.length / 2); var pointValue = this.splice(pointIndex, 1); var centerValue = pointValue[0]; var left = []; var right = []; for (var i = 0; i < this.length; i++) { var cur = this[i]; cur < centerValue ? left.push(cur) : right.push(cur); } return left.quickSort().concat(pointValue, right.quickSort()); } var ary = [3, 2, 1, 10, 7, 8, 9]; console.log(ary.quickSort());
var quick = function(arr) { if(arr.length <= 1){ return arr; var pivotIndex = Math.floor(arr.length / 2); var pivot = arr.splice(pivotIndex, 1)[0]; var left = []; var right = []; var same = []; ...
Array.prototype.quickSort = function() { var len = this.length if(len > 1) { var pivot = this[0] var left = [] var right = [] for(var i = 1; i < len; i++) { if(this[i] < pivot) { left.push(this[i]) ...
Array.prototype.quickSort = 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++) { ...
Array.prototype.quickSort = function () { if (this.length < 2) { return this; let pivot = this[0]; let left = []; let right = []; for (var i = 1; i < this.length; i++) { if (this[i] < pivot) { ...
Array.prototype.quickSort = function() if (this.length === 0) { return []; var left = []; var right = []; var pivot = this[0]; for (var i = 1; i < this.length; i++) { ...
Array.prototype.quickSort = function (comparator) { if (typeof comparator !== "function") { comparator = function (x, y) { if (x === y) { return 0; } else if (x < y) { return -1; } else { return 1; ...
Array.prototype.quickSort = function(start, len) { if (typeof len === "undefined") { len = this.length; if (len < 2) { return this; }; Array.prototype.swap = function (idx1, idx2) { ...
Array.prototype.quick_sort = function () { if (this.length < 2) { return this; } var pivot = this[Math.round(this.length / 2)]; return this.filter(x => x < pivot) .quick_sort() .concat(this.filter(x => x == pivot)) .concat(this.filter(x => x > pivot).quick_sort()); };
Array.prototype.quick_sort = function () { if (this.length < 2) { return this; } var pivot = this[Math.round(this.length / 2)]; return this.filter(x => x < pivot) .quick_sort() .concat(this.filter(x => x === pivot)) .concat(this.filter(x => x > pivot).quick_sort()); };