判斷版本號(hào)
function ComparativeVersion(oldV: string, newV: string) {
// 先把版本切成數(shù)組
let oldArr = oldV.split('.');
let newArr = newV.split('.');
// 循環(huán)對(duì)比每一位乖篷,發(fā)現(xiàn)新版本比較大毡庆,就 返回 true餐禁,新版本小就返回 false;
for (let index = 0; index < oldArr.length; index++) {
const oldItem = Number(oldArr[index]);
const newItem = Number(newArr[index]);
if (newItem > oldItem) {
return true;
}else if(newItem < oldItem){
return false;
}
}
// 若循環(huán)對(duì)比結(jié)束寞冯,說明版本一致,就返回false;
return false;
}