SOURCE

const insert_sort = list => {
    const len = list.length;

    for (let i = 1; i < len; i++) {

        let temp = list[i];

        let j = i - 1;
        while (j >= 0 && list[j] > temp) {
            list[j + 1] = list[j];
            j--;
        }
        list[j + 1] = temp;
    }

    return list;
}


const list = [10, 8, 7, 6];

console.log(insert_sort(list));
console 命令行工具 X clear

                    
>
console