Lobashov_Ivan_PIBD-21_IP/Lab3/node_modules/semver-compare/index.js

14 lines
372 B
JavaScript
Raw Permalink Normal View History

2024-01-10 22:39:31 +04:00
module.exports = function cmp (a, b) {
var pa = a.split('.');
var pb = b.split('.');
for (var i = 0; i < 3; i++) {
var na = Number(pa[i]);
var nb = Number(pb[i]);
if (na > nb) return 1;
if (nb > na) return -1;
if (!isNaN(na) && isNaN(nb)) return 1;
if (isNaN(na) && !isNaN(nb)) return -1;
}
return 0;
};