diff options
| author | Jez Ng | 2012-10-27 15:36:35 -0400 |
|---|---|---|
| committer | Jez Ng | 2012-10-29 17:53:16 -0400 |
| commit | c0af54eac713be14d1e3eceeca23139455abb408 (patch) | |
| tree | c6fee40a7169a6ee55721cc57594aaff71bad368 /lib | |
| parent | 22796c1676decbda4f2785f1cb10667ebaf941c7 (diff) | |
| download | vimium-c0af54eac713be14d1e3eceeca23139455abb408.tar.bz2 | |
Split out compareVersions into the Utils file.
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/utils.coffee | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/lib/utils.coffee b/lib/utils.coffee index c92fa1ff..e89d0aa2 100644 --- a/lib/utils.coffee +++ b/lib/utils.coffee @@ -111,6 +111,21 @@ Utils = # detects both literals and dynamically created strings isString: (obj) -> typeof obj == 'string' or obj instanceof String + + # Compares two version strings (e.g. "1.1" and "1.5") and returns + # -1 if versionA is < versionB, 0 if they're equal, and 1 if versionA is > versionB. + compareVersions: (versionA, versionB) -> + versionA = versionA.split(".") + versionB = versionB.split(".") + for i in [0...(Math.max(versionA.length, versionB.length))] + a = parseInt(versionA[i] || 0, 10) + b = parseInt(versionB[i] || 0, 10) + if (a < b) + return -1 + else if (a > b) + return 1 + 0 + # This creates a new function out of an existing function, where the new function takes fewer arguments. This # allows us to pass around functions instead of functions + a partial list of arguments. Function::curry = -> |
