SOURCE

let arr = [1,4,6,3,6,4,8,11,64,33,4,1]
// 冒泡排序
const bubbleSort = (arr)=>{
    const n = arr.length
    for(let i = n-1; i > 0; i--){
        for(let j = 0; j < i; j++){
            if(arr[j] > arr[j+1]){
                [arr[j],arr[j+1]] = 
                    [arr[j+1],arr[j]]
            }
        }
    }
}

// 选择排序
const selectSort = (arr)=>{
    const n = arr.length
    for(let i = 0; i < n-1; i++){
        let minIndex = i+1
        for(let j = i+1; j < n; j++){
            if(arr[j] < arr[minIndex]){
                minIndex = j
            }
        }
        [arr[minIndex],arr[i+1]] = 
            [arr[i+1],arr[minIndex]]
    }
}

// 插入排序
const insertSort = (arr)=>{
    const n = arr.length
    for(let i = 1; i < n; i++){
        for(let j = i-1; j >= 0; j--){
            if(arr[j] > arr[j+1]){
                [arr[j],arr[j+1]] = 
                    [arr[j+1],arr[j]]
            }else break
        }
    }
}

console.log(arr)
// bubbleSort(arr)
// selectSort(arr)
insertSort(arr)
console.log(arr)
console 命令行工具 X clear

                    
>
console