编辑代码


const selectSort = (arr, arrLen) => {
    if(arrLen < 0) {

    }

    for (let i = 0;i < arrLen;i++) {
        let maxIndex = i
        for (let j = i + 1;j < arrLen;j++) {
            if (arr[j] > arr[maxIndex]) {
                maxIndex = j
            }
        }
        if (maxIndex !== i) {
            let temp = arr[maxIndex]
            arr[maxIndex] = arr[i]
            arr[i] = temp
        }
        console.log(arr)
    }

}

const arr1 = [9,5,3,1,6,4,7,22,2]
selectSort(arr1,9)