function sort(arr){ if(arr.length === 1){ return arr; } //分成两部分 let mid = Math.floor(arr.length/2); let [part1,part2] = [sort(arr.slice(0,mid)),sort(arr.slice(mid))]; //对比+合并 let result = []; while(part1.length>0 && part2.length>0){ result.push((part1[0]<part2[0]?part1.shift():part2.shift())); } return [...result,...part1,...part2]; } console.log(sort([1,7,6,8,3]))