SOURCE

function expect(value) {
    return {
        toBe: (expectedValue) => {
            console.log(`expect ${value} to be ${expectedValue}`, value === expectedValue ? '✅' : '❌')
        }
    }
}

/**
 * 灵雀云前端面试题:版本号对比
 * 实现 compareVersion 函数,使测试用例能够返回正确的结果
 */

const version1 = '1.10';
const version2 = '1.10.2';
const version3 = '1.9.10';
const version4 = '2.0';
const version5 = '2.0.1';

function compareVersion(v1, v2) {

    return 0
}

// 期望以下测试用例能够通过
expect(compareVersion(version1, version2)).toBe(-1);
expect(compareVersion(version1, version3)).toBe(1);
expect(compareVersion(version1, version4)).toBe(-1);
expect(compareVersion(version1, version1)).toBe(0);
expect(compareVersion(version4, version5)).toBe(-1);
console 命令行工具 X clear

                    
>
console