<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<script>
function quchong(ary){
if(ary.length<1){ //如果数组就一项就直接给它返回
return ary;
}
let suoyin=Math.floor(ary.length/2);
let zhi=ary.splice(suoyin,1)[0];;
let left=[],right=[];
for(let i=0;i<ary.length;i++){
if(ary[i]<zhi){
left.push(ary[i]);
}else{
right.push(ary[i]);
}
}
return quchong(left).concat(zhi,quchong(right));
}
let s=[1,5,3,6,4,2]
let res=quchong(s);
console.log(res);
</script>
</body>
</html>a