SOURCE

let testArr = [5, 17, 1, 33, 2, 6, 20];
document.write(testArr + "<br/>");


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

document.write(insertionSort(testArr));
console 命令行工具 X clear

                    
>
console