semver compare
2022年5月1日小于 1 分钟
semver compare
Question
Please implement a function to compare 2 semver strings.
compare('12.1.0', '12.0.9')
// 1, meaning first one is greater
compare('12.1.0', '12.1.2')
// -1, meaning latter one is greater
compare('5.0.1', '5.0.1')
// 0, meaning they are equal.
Code
/**
* @param {string} v1
* @param {string} v2
* @returns 0 | 1 | -1
*/
function compare(v1, v2) {
// your code here
}