Skip to content

Instantly share code, notes, and snippets.

@prmichaelsen
Created October 4, 2024 19:11
Show Gist options
  • Save prmichaelsen/b1935b99ecba1a664c43e277dc7c3e1d to your computer and use it in GitHub Desktop.
Save prmichaelsen/b1935b99ecba1a664c43e277dc7c3e1d to your computer and use it in GitHub Desktop.
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