function computed(source, target) {
const a = source.split('.').map(Number); // 转换成数字数组
const b = target.split('.').map(Number);
// 获取数组位数
const maxLength = Math.Max(a.length, b.length);
for(let i = 0; i < maxLengt; i++) {
let num1 = a[i];
let num2 = b[i];
// 确认前一位和后一位的大小
if (num1 > num2) {
return -1
} else if (num1 < num2) {
return 1
}
}
}
computed('1.0.3', '1.0.5'); // 1
computed('1.1.3', '1.0.5'); // -1
computed('1.1.3', '1.1.5'); // 1