题解 | #密码验证合格程序#

密码验证合格程序

https://www.nowcoder.com/practice/184edec193864f0985ad2684fbc86841

const rl = require("readline").createInterface({ input: process.stdin });

rl.on('line',line => {
    console.log(isValid(line))
})

function isValid(str) {
    //长度
    if(str.length <= 8) {
        return 'NG'
    }
    //种类
    let count = 0
    if(/[a-z]/.test(str)) {
        count++
    }
    if(/[A-Z]/.test(str)) {
        count++
    }
    if(/\d/.test(str)) {
        count++
    }
    if(/[^a-zA-Z\d\s]/.test(str)) {
        count++
    }
    if(count < 3) {
        return 'NG'
    }
    //重复
    const obj = {}
    for(let i = 3;i < str.length / 2;i++) {
        let index = 0
        while(index < str.length - i) {
            let k = str.substring(index,index + i)
            if(obj[k]) {
                return 'NG'
            }else {
                obj[k] = 1
            }
            index++
        }
    }
    return 'OK'
}

全部评论

相关推荐

找只鸡:可以,直接拉黑这个邮箱
点赞 评论 收藏
分享
点赞 收藏 评论
分享
牛客网
牛客企业服务