We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 8d9d9ed commit b6b5af0Copy full SHA for b6b5af0
165-compare-version-numbers.js
@@ -0,0 +1,31 @@
1
+/**
2
+ * @param {string} version1
3
+ * @param {string} version2
4
+ * @return {number}
5
+ */
6
+const compareVersion = function(version1, version2) {
7
+ const fa = version1.split(".");
8
+ const sa = version2.split(".");
9
+ const len = Math.max(fa.length, sa.length);
10
+ if (fa.length < len) {
11
+ while (fa.length < len) {
12
+ fa.push("0");
13
+ }
14
15
+ if (sa.length < len) {
16
+ while (sa.length < len) {
17
+ sa.push("0");
18
19
20
+ while (sa.length > 0 && fa.length > 0) {
21
+ let fe = +fa.shift();
22
+ let se = +sa.shift();
23
+ if (fe > se) {
24
+ return 1;
25
26
+ if (fe < se) {
27
+ return -1;
28
29
30
+ return 0;
31
+};
0 commit comments