How to achieve version comparison with JavaScript
This article mainly introduces JavaScript how to achieve version comparison, the article introduces in great detail, has a certain reference value, interested friends must read it!
Version comparison function compareVersion (v1, v2) {
V1 = v1.split (".")
V2 = v2.split (".")
Var len = Math.max (v1.length, v2.length)
While (v1.length
< len) { v1.push("0"); } while (v2.length < len) { v2.push("0"); } for (var i = 0; i < len; i++) { var num1 = parseInt(v1[i]); var num2 = parseInt(v2[i]); if (num1 >Num2) {
Return 1
} else if (num1 < num2) {
Return-1
}
}
Return 0
} these are all the contents of the article "how to achieve version comparison in JavaScript". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!