题解 | #判断版本#
判断版本
https://www.nowcoder.com/practice/dcc4b011c86c454aa58cb1790a8cb760
<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8>
</head>
<body>
<script type="text/javascript">
const _shouldUpdate = (oldVersion, newVersion) => {
// 补全代码
let newArr = newVersion.split(".")
let oldArr = oldVersion.split(".")
let flag = false
for(let i=0;i<newArr.length;i++){
document.body.innerText+=(Number(newArr[i])>Number(oldArr[i]))
if(Number(newArr[i])>Number(oldArr[i])){
flag = true
}
}
return flag
}
_shouldUpdate('9.0.1','9.1.0');
</script>
</body>
</html>
<html>
<head>
<meta charset=utf-8>
</head>
<body>
<script type="text/javascript">
const _shouldUpdate = (oldVersion, newVersion) => {
// 补全代码
let newArr = newVersion.split(".")
let oldArr = oldVersion.split(".")
let flag = false
for(let i=0;i<newArr.length;i++){
document.body.innerText+=(Number(newArr[i])>Number(oldArr[i]))
if(Number(newArr[i])>Number(oldArr[i])){
flag = true
}
}
return flag
}
_shouldUpdate('9.0.1','9.1.0');
</script>
</body>
</html>