编辑代码

function insertionSort(arr) {
    const n = arr.length;
    for (let i = 1; i < n; i++) {
        const current = arr[i];
        let j = i - 1;
        while (j >= 0 && arr[j] > current) {
            arr[j + 1] = arr[j];
            j--;
        }
        arr[j + 1] = current;
    }
}


const test1 = [5, 2, 9, 3, 4];
insertionSort(test1);
console.log("Test 1:", test1); 

const test2 = [1, 0, 0, 1, 1];
insertionSort(test2);
console.log("Test 2:", test2); 

const test3 = [3, 2, 1];
insertionSort(test3);
console.log("Test 3:", test3);