SOURCE

const shellSort = array => {
    const {length} = array
    for(let gap = Math.floor(length / 2) ; gap > 0; gap = Math.floor(gap / 2)) {
        for(let i = gap; i < length; i++) {
            let temp = array[i]
            for(var j = i - gap; j >= 0 && array[j] > temp; j-= gap) {
                array[j + gap] = array[j]
            }
            array[j + gap] = temp
        }
    }
    return array
}

console.log(shellSort([3,44,38,5,47,15,36,26,27,2,46,4,19,50,48]))
console 命令行工具 X clear

                    
>
console