Created
January 9, 2018 05:39
-
-
Save aizigao/e487ef82ff07196eefe8cf36c556646c to your computer and use it in GitHub Desktop.
js 对比版本号
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const isNewVersion = (oldStr, newStr, contrastIdx = 0) => { | |
const oldArr = [0, 0, 0] | |
const newArr = [0, 0, 0] | |
oldArr.splice(0, oldStr.split('.').length, ...oldStr.split('.')) | |
newArr.splice(0, newStr.split('.').length, ...newStr.split('.')) | |
const oldTag = parseInt(newArr[contrastIdx], 10) | |
const newTag = parseInt(oldArr[contrastIdx], 10) | |
if (oldTag === newTag) { | |
if (contrastIdx === 2) { | |
return false | |
} | |
return isNewVersion(oldStr, newStr, contrastIdx + 1) | |
} else if (oldTag < newTag) { | |
return false | |
} | |
return true | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment