题解 | #密码强度等级#

密码强度等级

https://www.nowcoder.com/practice/52d382c2a7164767bca2064c1c9d5361

这应该算是比较简洁的一个版本了吧 欢迎有更好方法的朋友指正 完整代码如下:
let res = 0;
while(line = readline()) {
    line.length > 8 ? res += 25 : line.length > 4 ? res += 10 : res += 5;
    line.match(/(?=.*[a-z])(?=.*[A-Z])^.+$/) ? res += 20 : res += 10;
    //下面这两步我一直想去掉第一个条件,但是一旦去掉系统就会报错‘Can't read property 'length' of null’;没办法只能加上了
    line.match(/\d/g) ? (line.match(/\d/g).length > 1 ? res += 20 : res += 10) : res = res;
    line.match(/\W/g) ? (line.match(/\W/g).length > 1 ? res += 25 : res += 10) : res = res;
    //这个也是相对来说比较简洁的方法了
    line.match(/(?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?=.*\W)^.+$/) ? res += 5
        : line.match(/(?=.*\d)(?=.*[A-Za-z])(?=.*\W)^.+$/) ? res += 3
        : line.match(/(?=.*\d)(?=.*[A-Za-z])^.+$/) ? res += 2
        : res = res;
}
//最后采用了一个for循环来显示结果
let arr1 = [90, 80, 70, 60, 50, 25, 0];
let arr2 = ['VERY_SECURE', 'SECURE', 'VERY_STRONG', 'STRONG', 'AVERAGE', 'WEAK', 'VERY_WEAK'];
for (let i = 0; i < 7; i++) {
    if (res >= arr1[i]) {
        console.log(arr2[i]);
        break;
    }
}


全部评论

相关推荐

我是没经验的毕业生,这啥情况啊会不会是hr在刷kpi
JamesGosli...:字节boss属于是群发了,我都快入职字节了,其他部门还在和我boss打招呼
点赞 评论 收藏
分享
评论
1
1
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务