Im writting a function to compare 2 versions, and return true if the second is bigger then first version.
but my algorithm have a "hole", and I cant figure out how fix.
function compareversion(version1,version2){
var result=false;
if(typeof version1!=='object'){ version1=version1.toString().split('.'); }
if(typeof version2!=='object'){ version2=version2.toString().split('.'); }
for(var i=0;i<(Math.max(version1.length,version2.length));i++){
if(version1[i]==undefined){ version1[i]=0; }
if(version2[i]==undefined){ version2[i]=0; }
if(version1[i]<version2[i]){
result=true;
break;
}
}
return(result);
}
this exemples return as expected
compareversion('1','1') //false
compareversion('1','1.0.0') //false
compareversion('2.0','1.0.0') //false
compareversion('1.1','1.2') //true
compareversion('1','1.0.0.1') //true
but this
compareversion('1.1.0','1.0.1') //return true but should be false