-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path版本号.html
79 lines (67 loc) · 2.18 KB
/
版本号.html
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script>
// var compareVersion = function (version1, version2) {
// let arr1 = version1.split(".");
// let arr2 = version2.split(".");
// let len = Math.max(arr1.length, arr2.length);
// for (let i = 0; i < len; i++) {
// let data1 = 0,
// data2 = 0;
// if (i < arr1.length) {
// data1 = parseInt(arr1[i]);
// }
// if (i < arr2.length) {
// data2 = parseInt(arr2[i]);
// }
// if (data1 < data2) {
// return -1;
// } else if (data1 > data2) {
// return 1;
// }
// }
// return 0;
// };
function compareVersion(version1, version2) {
let arr1 = version1.split(".");
let arr2 = version2.split(".");
let len = Math.max(arr1.length, arr2.length);
for (let i = 0; i < len; i++) {
let d1 = 0,
d2 = 0;
if (i < arr1.length) {
d1 = parseInt(arr1[i]);
}
if (i < arr2.length) {
d2 = parseInt(arr2[i]);
}
if (d1 < d2) {
return -1;
} else if (d1 > d2) {
return 1;
}
}
return 0;
}
let arr = ["1.5.1", "1.5", "6", "3.3.3.3.3"];
arr.sort(compareVersion);
console.log(arr);
// console.log(compareVersion("1.5.1", "1.5"));
function testType(type) {
// if (typeof type != 'object') {
// return type;
// }
// if (type === null) return null;
let str = Object.prototype.toString.call(type);
return str.slice(8, str.length - 1);
}
// console.log(testType(null));
</script>
</head>
<body>
</body>
</html>