function* walk(str){
let terminals = ['.','-']
let part =''
for(var i =0;i<str.length;i++){
if(terminals.includes(str[i])){
yield part
part=''
}else{
part +=str[i]
}
}
if(part){
yield part
}
}
let a ="1.1.1.a"
let b = "1.1.1-apha.1"
const compare =(str1,str2)=>{
if(str1.length>str2.length) [str1,str2] =[str2,str1] //保证循环长的字符串
let interator1 = [...walk(str1)]
let interator2 = [...walk(str2)]
let res =''
for(const index1 in interator1){
for(const index2 in interator2){
if(index1 != index2) continue
if(interator1[index1] ==interator2[index2]) continue
return +interator1[index1]>+interator2[index2]?str1:str2
}
}
return str2
}
console.log(compare(a,b))
console