Created
April 6, 2016 03:20
-
-
Save joeylin/1a731791827477a29c21abdece504433 to your computer and use it in GitHub Desktop.
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
function versionCompare(a, b) { | |
var i; | |
var len; | |
if (typeof a + typeof b !== 'stringstring') { | |
return false; | |
} | |
a = a.split('.'); | |
b = b.split('.'); | |
len = Math.max(a.length, b.length); | |
for (i = 0; i < len; i++) { | |
if ((a[i] && !b[i] && parseInt(a[i]) > 0) || (parseInt(a[i]) > parseInt(b[i]))) { | |
return 1; | |
} else if ((b[i] && !a[i] && parseInt(b[i]) > 0) || (parseInt(a[i]) < parseInt(b[i]))) { | |
return -1; | |
} | |
} | |
return 0; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment