From c0af54eac713be14d1e3eceeca23139455abb408 Mon Sep 17 00:00:00 2001 From: Jez Ng Date: Sat, 27 Oct 2012 15:36:35 -0400 Subject: Split out compareVersions into the Utils file. --- lib/utils.coffee | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'lib/utils.coffee') 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 = -> -- cgit v1.2.3