const lines = ["5.2", "5.1a"];
const lines1 = ["5.6.1", "5.6.2a"];
const lines2 = ["5.6.8.a", "5.6.8.0a"];
const lines3 = ["5.06.08.a", "5.6.8.0a"];
const lines4 = ["5", "5.0.0.0"];
function solution(lines) {
const [verson1, version2] = lines;
if (!isValid(verson1) || !isValid(version2)) return 0;
const str1 = verson1.replace(/[\.0]/g, "");
const str2 = version2.replace(/[\.0]/g, "");
return parseInt(str1) !== parseInt(str2)
? parseInt(str1) > parseInt(str2)
? 1
: -1
: 0;
console.log(str1, str2);
function isValid(ver) {
if (/[^0-9a-zA-Z.]/.test(ver)) return false;
const arr = ver.split(".");
if (arr.length < 1) return false;
return true;
}
}
console.log(solution(lines));
/*
5.2
5.1a
=> 1
5.6.1
5.6.2a
=>
-1
5.6.8.a
5.6.8.0a
=>
0
const lines3 = ["5.06.08.a", "5.6.8.0a"]; 预计 0
const lines4 = ["5", "5.0.0.0"]; 预计 0
*/