function sort(arr){ if(arr.length<=1){ return arr; } var num = Math.floor(arr.length/2); var numValue = arr.splice(num,1); var left = []; var right = []; for(var i = 0; i < arr.length; i++){ if(arr[i]<numValue){ left.push(arr[i]); }else{ right.pu…
function quickSort(arr){ if(arr.length<=1){ return arr; } var arrIndex=Math.floor(arr.length/2); var x=arr.splice(arrIndex,1)[0]; var left=[]; var right=[]; for(var i=0;i<arr.length;i++){ if(arr[i]<x){ left.push(arr[i]); } else{ right.push(arr[i]…
var quickSort = 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 = []; for (var i = 0; i < arr.length; i++){ if (arr[i] < pivot) {…
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 && le…