Skip to content

Commit 19f756e

Browse files
committed
Update index.ts
1 parent 0597d65 commit 19f756e

File tree

1 file changed

+15
-14
lines changed

1 file changed

+15
-14
lines changed

compare-version-numbers/index.ts

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
1-
export default function compareVersion(version1: string, version2: string): number {
2-
const a=version1.split(".").map(Number)
1+
export default function compareVersion(
2+
version1: string,
3+
version2: string,
4+
): number {
5+
const a = version1.split(".").map(Number);
36

4-
const b=version2.split(".").map(Number)
7+
const b = version2.split(".").map(Number);
58

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
9+
for (let i = 0; i < Math.max(a.length, b.length); i++) {
10+
const q = a[i] ?? 0;
11+
12+
const w = b[i] ?? 0;
13+
14+
if (q > w) return 1;
15+
if (q < w) return -1;
16+
}
17+
return 0;
1718
}

0 commit comments

Comments
 (0)