JavaScript generic determines whether the version number is code between version ranges

Source: Internet
Author: User
Tags ranges

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.