Skip to content

Instantly share code, notes, and snippets.

@sebringj
Last active March 10, 2021 17:57
Show Gist options
  • Save sebringj/0d7ac14fab55bd5bc31f3dfd6c81e01b to your computer and use it in GitHub Desktop.
Save sebringj/0d7ac14fab55bd5bc31f3dfd6c81e01b to your computer and use it in GitHub Desktop.
function versionToNumber(version) {
return version
.split('.')
.reverse()
.map((v, i) => parseInt(v, 10) * Math.pow(1000, i))
.reduce((a, v) => a + v);
}
@sebringj
Copy link
Author

This allows you to compare software versions easily like

const isHigherVersion = versionToNumber('1.3.4') > versionToNumber('2.3.2');

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment