编辑代码

const selectionSort = (arr: number[]): void => {
    const arrLen: number = arr.length;
    for (let i: number = 0; i < arrLen - 1; ++i) {
        let minIndex: number = i;
        for (let j: number = i + 1; j < arrLen; ++j) {
            minIndex = arr[minIndex] > arr[j] ? j : minIndex;
        }
        if (minIndex != i) {
            const tmp: number = arr[i];
            arr[i] = arr[minIndex];
            arr[minIndex] = tmp;
        }
        console.log(arr);
    }
}

const arr: number[] = [4, 5, 6, 3, 2, 1];
console.log(arr);
selectionSort(arr);