1
var compareVersion = function (version1, version2) {2
const v1 = version1.split(".");3
const v2 = version2.split(".");5
let max = Math.max(v1.length, v2.length);7
for (let i = 0; i < max; i++) {9
// if both v1 and v2 are present10
if (+v1[i] > +v2[i]) return 1;11
else if (+v1[i] < +v2[i]) return -1;12
} else if (v1[i] && +v1[i] !== 0) {13
// if v1 is larger than v2 but make sure those digits are not 0.15
} else if (v2[i] && +v2[i] !== 0) {16
// if v2 is larger than v1 but make sure those digits are not 0.