constmergeSort=(arr)=>{let len = arr.length
if(len <2)return arr
let mid = Math.floor(len /2)let left = arr.slice(0,mid)let right = arr.slice(mid)returnmerge(mergeSort(left),mergeSort(right))}constmerge=(left,right)=>{let res =[]while(left.length && right.length){if(left[0]>= right[0]){
res.push(right.shift())}else{
res.push(left.shift())}}if(left.length){
res =res.concat(left)}if(right.length){
res =res.concat(right)}return res
}let arr =[2,6,4,2,1,5,79,9,3,2]
arr =mergeSort(arr)
console.log(arr)
冒泡排序
functionmaoPao(arr){let len = arr.length
for(let i =0; i < len; i++){for(let j =0; j < len - i -1; j++){if(arr[j +1]< arr[j])[arr[j],arr[j +1]]=[arr[j +1],arr[j]]}}}