Skip to content

Instantly share code, notes, and snippets.

@JoshuaGross
Created January 13, 2016 00:26
Show Gist options
  • Save JoshuaGross/29e757ab31f64cc5f651 to your computer and use it in GitHub Desktop.
Save JoshuaGross/29e757ab31f64cc5f651 to your computer and use it in GitHub Desktop.
Sort semantic version numbers.
// 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