Get the App
SLTechnology News&Howtos  ›  Development  › 

How to achieve version comparison with JavaScript

Shulou Source: shulou.com Published: 2022-06-01 02:56:37 09月22日 Update

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!

Tags: Version content article value interest guy partner more knowledge industry information information channel channel reference help Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno NVidia Apple Redmi Shulou Technology OPPO Reno