* Compare two semantic version numbers and return the difference. * @param {string} a Version number a. * @param {string} b Version number b. * @returns {number} A positive number if a is larger than b, a negative * number if a is smaller and 0 if they are the same
(a, b)
| 161 | * number if a is smaller and 0 if they are the same |
| 162 | */ |
| 163 | function cmpVersions (a, b) { |
| 164 | let i, diff; |
| 165 | const regExStrip0 = /(\.0+)+$/; |
| 166 | const segmentsA = a.replace(regExStrip0, "").split("."); |
| 167 | const segmentsB = b.replace(regExStrip0, "").split("."); |
| 168 | const l = Math.min(segmentsA.length, segmentsB.length); |
| 169 | |
| 170 | for (i = 0; i < l; i++) { |
| 171 | diff = parseInt(segmentsA[i], 10) - parseInt(segmentsB[i], 10); |
| 172 | if (diff) { |
| 173 | return diff; |
| 174 | } |
| 175 | } |
| 176 | return segmentsA.length - segmentsB.length; |
| 177 | } |
| 178 | |
| 179 | /** |
| 180 | * Start the core app. |