Skip to content

Commit 0597d65

Browse files
authored
Create index.ts
1 parent c25be85 commit 0597d65

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

compare-version-numbers/index.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
export default function compareVersion(version1: string, version2: string): number {
2+
const a=version1.split(".").map(Number)
3+
4+
const b=version2.split(".").map(Number)
5+
6+
for(let i =0 ;i<Math.max(a.length,b.length);i++){
7+
8+
const q=a[i]??0
9+
10+
const w=b[i]??0
11+
12+
if(q>w)return 1
13+
if(q<w)return -1
14+
15+
}
16+
return 0
17+
}

0 commit comments

Comments
 (0)