题解 | #密码验证合格程序#
密码验证合格程序
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' }