题解 | #判断版本#
判断版本
https://www.nowcoder.com/practice/dcc4b011c86c454aa58cb1790a8cb760
const _shouldUpdate = (oldVersion, newVersion) => { // 补全代码 const olds = oldVersion.split('.'); const news = newVersion.split('.'); let num = 0 for (let i = 0; i < 3; i++) { if (news[i] > olds[i] && i == num) { return true; break; } else if (news[i] == olds[i] && i == num) { num++; continue; } else if (news[i] < olds[i] && i == num) { return false; break; } } }
当然还有更好的解答方法,但这种方法最常规,也最容易理解