SOURCE

const arr = [
    '1.1',
    '2.3.3',
    '4.3.5',
    '0.3.1',
    '0.302.1',
    '4.20.0',
    '4.3.5.1',
    '1.2.3.4.5'
];
arr.sort((a, b) => {
    // let i = 0;
    // const arr1 = a.split('.');
    // const arr2 = b.split('.');
    // console.log(arr1, arr2)
    // while (true) {
    //     const s1 = arr1[i];
    //     const s2 = arr2[i++];
    //     console.log(s1, s2, 'sssssss')

    //     if (s1 === undefined || s2 === undefined) {
    //         return arr2.length - arr1.length;
    //     }

    //     if (s1 === s2) continue;

    //     return s2 - s1;
    // }
    const handleStr = (str) => {
        return str.split('.').map(item => Number(item))
    }
    const v1 = handleStr(a), v2 = handleStr(b);
    console.log(v1, v2, 'vvvvv')
    const len = Math.max(v1.length, v2.length);
    for (let i = 0; i < len; i++) {
        let a1 = v1[i] ? v1[i] : 0;
        let b1 = v2[i] ? v2[i] : 0;
        if (a1 !== b1) {
            // 顺序输出
            return a1 - b1
        }

    }
});

console.log(arr)
console 命令行工具 X clear

                    
>
console