/*
* 先去找数组中间一项,把这一项拿出来; 用拿出之后的数组中的每一项跟 拿出的这一项比较;比这项大的放到一个数组; 小的放到另外一个数组
* 接着对着两个数组做上述同样的操作;
* */
function quickSort(ary) {
if(ary.length <=1){
return ary
};
var n = parseInt(ary.length/2);
var cur = ary.splice(n,1)[0];
var left = [],right = [];
for(var i = 0; i < ary.length; i++){
if(ary[i] < cur){
left.push(ary[i])
}else {
right.push(ary[i])
}
}
return quickSort(left).concat(cur,quickSort(right));
}
var ary1 = [5,3,7,2,8,4,2];
var temp = quickSort(ary1);
console.log(temp);