实现方案:在lineevent中暂存输入的line,使用debounce防抖,暂存一段时间后,分批处理以一道上机试题为例,描述一下密码要求:1.长度超过8位2.包括大小写字母。数字。其他符号,至少以上四种类型中的三种3.不能有长度大于2的相同子串重复输入说明:一组或多组长度大于2的字符串,每组占一行输出说明:如果满足要求输出:OK,否则输出NG示例1输入:021Abc9000021Abc9Abc1021ABC9000021$bc9000复制输出:OKNGNGOKconstreadline=require('readline');functionisRepeatStr(str){letlen=str.length-2;for(leti=0;i0)返回真;如果(tmpStr2.indexOf(subStr)>0)返回真;}returnfalse;}functionstrWeight(str){让numWeight=0;让upperWeight=0;让较低的重量=0;让其他重量=0;str.split('').forEach(item=>{if(isNum(item)){numWeight=numWeight?numWeight:1;}elseif(isUpperChar(item)){upperWeight=upperWeight?upperWeight:1;}elseif(isLowerChar(item)){lowerWeight=lowerWeight?lowerWeight:1;}elseotherWeight=otherWeight?otherWeight:1;})返回numWeight+upperWeight+lowerWeight+otherWeight;}functionisNum(str){returnstr.match(/[0-9]/)!=null;}functionisUpperChar(str){returnstr.match(/[A-Z]/)!=null;}functionisLowerChar(str){returnstr.match(/[a-z]/)!=null;}functiondebounce(func,delay){vartimer;返回函数(){varcontext=this;清除超时(计时器);timer=setTimeout(function(){func.apply(context,arguments);timer=undefined;},delay||20);};};functionmyProcess(str){return(strWeight(str)>=3)&&(!isRepeatStr(str))&&(str.length>8);}constrl=readline.createInterface({输入:过程。标准输入,输出:process.stdout});letglobalArray=[];functionprocessAll(){globalArray.forEach(line=>{if(myProcess(line)==true){console.log('OK');}else{console.log('NG');}})}letdelayProcess=debounce(processAll,20);rl.on('line',function(line){globalArray.push(line);delayProcess();});