MBTI人格测试 uniapp

compareVersion.js 473B

12345678910111213141516171819202122232425
  1. function compareVersion(v1, v2) {
  2. if (v1 == v2) {
  3. return 0;
  4. }
  5. const vs1 = v1.split(".").map(a => parseInt(a));
  6. const vs2 = v2.split(".").map(a => parseInt(a));
  7. const length = Math.min(vs1.length, vs2.length);
  8. for (let i = 0; i < length; i++) {
  9. if (vs1[i] > vs2[i]) {
  10. return 1;
  11. } else if (vs1[i] < vs2[i]) {
  12. return -1;
  13. }
  14. }
  15. if (length == vs1.length) {
  16. return -1;
  17. } else {
  18. return 1;
  19. }
  20. }
  21. export default compareVersion