Last active
February 26, 2018 07:09
-
-
Save jalalazimi/e6a01f0a259670f73d5e14a8930e0110 to your computer and use it in GitHub Desktop.
compareVersions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function compareVersions(version1,version2){ | |
| function splitVersion(version){ | |
| if(typeof version !== 'string'){ throw ('sting is valid for version!'); } | |
| return version.toString().split('.'); | |
| } | |
| function _checkValue(arr){ | |
| return val ? val : 0; | |
| } | |
| var result=false; | |
| var version1=splitVersion(version1); | |
| var version2=splitVersion(version2); | |
| for(var i=0,_versionLength=Math.max(version1.length,version2.length);i<_versionLength;i++){ | |
| version1[i]=_checkValue(version1[i]) | |
| version2[i]=_checkValue(version2[i]) | |
| if(version1[i]<version2[i]){ | |
| result=true; | |
| break; | |
| } | |
| if(version1[i]!=version2[i]){ | |
| break; | |
| } | |
| } | |
| return result; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment