function compareVersion(newVersion, currentVersion) { const v1 = newVersion.split('.'); const v2 = currentVersion.split('.'); for (let i = 0; i < v1.length || i < v2.length; i++) { let x = 0, y = 0; if (i < v1.length) { x = parseInt(v1[i]); } if (i < v2.length) { y = parseInt(v2[i]) } if (x > y) return 1; if (x < y) return -1; } return 0; } let v1 = '3.34.001', v2 = '3.34.010'; console.log(compareVersion(v1, v2));
标签:return,版本号,APP,v2,v1,length,let,前端 From: https://www.cnblogs.com/aishangliming/p/17117158.html