JS快排
1 var quicksort = function(arr){ 2 if(arr.length <= 1){ 3 return arr; 4 } 5 var pivotIndex = matn.floor(arr.length/2); 6 var pivot = arr.splice(pivotIndex,1)[0]; 7 var left = []; 8 var right = []; 9 for (var i = 0; i < arr.length; i++){ 10 if(arr[i] < pivot){ 11 left.push(arr[i]); 12 }else{ 13 right.push(arr[i]); 14 } 15 } 16 } 17 18 return quicksort(left).concat([pivot], quicksort(right));
卡卡,你好吗