-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.ts
More file actions
33 lines (25 loc) · 685 Bytes
/
index.ts
File metadata and controls
33 lines (25 loc) · 685 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
function compareVersion(version1:string,version2:string):number
{
const v1:number[]=version1.split('.').map((item)=>Number.parseInt(item));
const v2:number[]=version2.split('.').map((item)=>Number.parseInt(item));
return compare(v1,v2);
}
function compare(v1:number[],v2:number[]):number
{
let max:number=Math.max(v1.length,v2.length);
for(let i=0;i<max;i++)
{
let current1:number=v1[i] || 0;
let current2:number=v2[i] || 0;
if(current1>current2)
{
return 1;
}
if(current1<current2)
{
return -1;
}
}
return 0;
}
export {compareVersion};