Last active
October 10, 2015 09:22
-
-
Save ramesaliyev/040330ecd1961f30f14e to your computer and use it in GitHub Desktop.
JavaScript Version Script Comparison
This file contains 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
/** | |
* if v2 version value bigger than v1, returns true. otherwise returns false. | |
* | |
* Version part lengths should be equal. | |
* | |
* Examples: | |
* isVersionNewer('1', '2'); -> true | |
* isVersionNewer('1.0', '2.0'); -> true | |
* isVersionNewer('2.0.1', '2.0.0'); -> false | |
* isVersionNewer('3.2.1.0', '3.2.1.1'); -> true | |
* | |
*/ | |
function isVersionNewer(v1, v2){ | |
v1 = v1.split('.'); | |
v2 = v2.split('.'); | |
for(var i = 0; i < v1.length; i++){ | |
if (+v2[i] > +v1[i]) return true; | |
if (+v2[i] < +v1[i]) return false; | |
} | |
return false; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment