SOURCE

let arr = [22,12,44,33,7,40,5]
console.log('befor sort'+[...arr])
function selctionSort(arr){
    let index
    let value
    for(let i =0;i<arr.length-2;i++){
        index = i
        value = arr[index]
        for(let j=i+1;j<arr.length;j++){
            if(arr[j]<value){
                index=j
                value=arr[j]
            }
        }
        arr[i]=arr[i]+arr[index]
        arr[index]=arr[i]-arr[index]
        arr[i]=arr[i]-arr[index]
        console.log([...arr])
    }
}
selctionSort(arr)
console.log('after sort'+[...arr])
console 命令行工具 X clear

                    
>
console