Created
January 13, 2016 00:26
-
-
Save JoshuaGross/29e757ab31f64cc5f651 to your computer and use it in GitHub Desktop.
Sort semantic version numbers.
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
// Sort semantic version numbers that look like this: | |
// 0.21 | |
// 0.21.4.3 | |
// 0.21.4-18bdje | |
function (a, b) { | |
a = a.split(/[-\.]/); | |
b = b.split(/[-\.]/); | |
for (var i = 0; i < a.length && i < b.length; i++) { | |
if (parseFloat(a[i]) > parseFloat(b[i])) { | |
return 1; | |
} | |
if (parseFloat(a[i]) < parseFloat(b[i])) { | |
return -1; | |
} | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment