Last active
December 15, 2015 20:41
-
-
Save bloodyowl/5320462 to your computer and use it in GitHub Desktop.
v.js
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
| /* | |
| v.js | |
| Is the version that I use ahead from the one I expected ? | |
| 123 bytes | |
| ## Usage | |
| v(actual, expected) | |
| e.g. | |
| v("1.2.3", "1.7.3") // false | |
| v("1.7.3", "1.7.3") // true | |
| v("1.8.3", "1.7.3") // true | |
| v("1.8.3", "1.8.10") // false | |
| */ | |
| function v(a,b){for(var c=".",d=b.split(c),e=a.split(c),f=0;3>f;f++){if(c=+d[f]-e[f],0>c)return!0;if(c>0)break}return 3==f} | |
| /* explanation */ | |
| function v(v, s){ | |
| var r = "." // separator | |
| , m = s.split(r) | |
| , a = v.split(r) | |
| , i = 0 | |
| for(;i < 3; i++) { | |
| r = (+m[i] - a[i]) // compare versions | |
| if(r < 0) return !0 // if stricly superior, version is ahead | |
| if(r > 0) break // if strictly inferior, version is obsolete | |
| } | |
| return i == 3 // check if a break occured | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment