题解 | #判断版本#
判断版本
https://www.nowcoder.com/practice/dcc4b011c86c454aa58cb1790a8cb760
函数代码如下
const _shouldUpdate = (oldVersion, newVersion) => { // 补全代码 //String.prototype.replace("待替换字符或正则表达式","替换的字符") //正则匹配表达式 let reg = /\./g //转换成数字进行大小的比较 const oldV = Number( oldVersion.replace(reg,"") ) const newV = Number( newVersion.replace(reg,"") ) return newV > oldV ? true : false }