If the general judgment version number is between the two, it can also be used to determine whether it is greater than a certain version number, less than reverse.
1 varAPP = {};2 3 //determines whether the specified version is 1.0.2 between version ranges 3.1.64App.betweenversion =function(curr,start,end,separator) {5 if(Curr = = Start | | curr = =end) {6 return true;7 }8 9 varSeparator = Separator | | ‘.‘;Ten varCurr =Curr.split (separator); One varStart =Start.split (separator); A varEnd =End.split (separator); - varGtstart =false; - varLtend =false; the -Gtstart =app.gttargetversion (App.compareversionele (Curr,start)); - - if(!Gtstart) { + return false; - } + A return!app.gttargetversion (App.compareversionele (curr,end)); at - }; -App.compareversionele =function(curr,target) { - varLen =curr.length; - vartemp = []; - varLeft,right; in - for(vari=0;i<len;i++){ to +left = +Curr[i]; -right = +Target[i]; the * if(left = =Right ) { $Temp.push (0);Panax Notoginseng}Else if(Left >Right ) { -Temp.push (1); the}Else{ +Temp.push (-1); A } the } + returntemp; - }; $ $App.gttargetversion =function(arr) { - varres =true; - varCurr,next; the - for(vari=0,len=arr.length;i<len;i++){WuyiCurr =Arr[i]; theNext = arr[i+1]; - Wu if(curr>next) { - if(Curr = = 0){ Aboutres =false; $ Break; - } - if(Curr = = 1){ -res =true; A Break; + } the -}Else if(Curr = =next) { $ if(Curr = =-1){ theres =false; the Break; the } the if(Curr = = 1){ -res =true; in Break; the } the}Else{ About if(Curr = =-1){ theres =false; the Break; the } + if(Curr = = 0){ -res =true; the Break;Bayi } the } the } - //Console.log (res); - returnRes; the } the the varres = app.betweenversion (' 1.2.100.10 ', ' 1.3.10.2 ', ' 3.1.1.16 ', '. ')); theConsole.log (RES);
The current project needs to determine whether the specified version in the two version of the demand, Baidu Google to find a circle, the code is limited, can not be universal, or even a bunch of wrong things around ...
There are two main points of the current method, one is the need to convert the cut version number to a numeric array, there is a comparison of the size of the time to 1 0 13 numeric comparison, so that regardless of the version number of the partition, the overall divided into several paragraphs, can be correctly compared.
JavaScript generic determines whether the version number is code between version ranges