Skip to content

Commit

Permalink
update compare function
Browse files Browse the repository at this point in the history
  • Loading branch information
syt2 committed Dec 25, 2023
1 parent dc9320d commit d73a08c
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions src/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,10 @@ export function compareVersion(versionA: string, versionB: string): number {
const partsA = versionA.toLowerCase().replace('v', '').split('.')
const partsB = versionB.toLowerCase().replace('v', '').split('.')

for (let i = 0; i < 3; i++) {
if (partsA[i] < partsB[i]) {
return -1;
} else if (partsA[i] > partsB[i]) {
return 1;
}
for (let i = 0; i < Math.max(partsA.length, partsB.length); i++) {
const a = i < partsA.length ? partsA[i] : '0', b = i < partsB.length ? partsB[i] : '0';
if (a < b) { return -1; }
if (a > b) { return 1; }
}
return 0; // 版本号相同
}
Expand Down

0 comments on commit d73a08c

Please sign in to comment.