index.js 372 B

1234567891011121314
  1. module.exports = function cmp (a, b) {
  2. var pa = a.split('.');
  3. var pb = b.split('.');
  4. for (var i = 0; i < 3; i++) {
  5. var na = Number(pa[i]);
  6. var nb = Number(pb[i]);
  7. if (na > nb) return 1;
  8. if (nb > na) return -1;
  9. if (!isNaN(na) && isNaN(nb)) return 1;
  10. if (isNaN(na) && !isNaN(nb)) return -1;
  11. }
  12. return 0;
  13. };