Created
October 4, 2024 19:11
-
-
Save prmichaelsen/b1935b99ecba1a664c43e277dc7c3e1d 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 compareSemver(a: string, b: string) { | |
const aSemver = a.split('-')[1].split('.'); | |
const bSember = b.split('-')[1].split('.'); | |
for (let i = 0; i < 3; i++) { | |
const aPart = parseInt(aSemver[i], 10); | |
const bPart = parseInt(bSember[i], 10); | |
if (aPart > bPart) { | |
return 1; | |
} else if (aPart < bPart) { | |
return -1; | |
} | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment