Comparing version numbers with JavaScript
A small review;


Once you know that one version digit is larger than the other, you can exit immediately
You did not declare i with const or let
I would advise the use of a beautifier for your code, it's a bit compact in some places
The code does not handle well versions with different counts of digits
You should always pass the base, when you call parseInt


I wrote an alternative version with 2 extra tests;



function checkVersion(a, b) {
    const x = a.split('.').map(e =&gt; parseInt(e, 10));
    const y = b.split('.').map(e =&gt; parseInt(e, 10));

    for (const i in x) {
        y[i] = y[i] || 0;
        if (x[i] === y[i]) {
            continue;
        } else if (x[i] &gt; y[i]) {
            return 1;
        } else {
            return -1;
        }
    }
    return y.length &gt; x.length ? -1 : 0;
}

console.log(checkVersion("1.2.2", "1.2.0"), 1); // returns 1 as expected
console.log(checkVersion("1.0.5", "1.1.0"), -1); // returns -1 as expected
console.log(checkVersion("1.0.5", "1.00.05"), 0); // returns 0 as expected
console.log(checkVersion("0.9.9.9.9.9.9", "1.0.0.0.0.0.0"), -1) // returns -1 as expected;
console.log(checkVersion("1.0.5", "1.0"), 1); // returns 1 as expected
console.log(checkVersion("1.0", "1.0.5"), -1); // returns -1 as expected
console.log(checkVersion('2019.09', '2019.9'), 0) // returns 0