We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
functionminimumNumber(n,password){// Return the minimum number of characters to make the password strongconstNUM="0123456789";constLOW="abcdefghijklmnopqrstuvwxyz";constUPP="ABCDEFGHIJKLMNOPQRSTUVWXYZ";constSPE="!@#$%^&*()-+";constTYPES=[NUM,LOW,UPP,SPE];constMIN_LENGTH=6;lettypesIncluded=0;lethasNum=false,hasLow=false,hasUpp=false,hasSpe=false;letresult=0;for(letitemofpassword){if(NUM.indexOf(item)!==-1&&!hasNum){hasNum=true;typesIncluded++;continue;}if(LOW.indexOf(item)!==-1&&!hasLow){hasLow=true;typesIncluded++;continue;}if(UPP.indexOf(item)!==-1&&!hasUpp){hasUpp=true;typesIncluded++;continue;}if(SPE.indexOf(item)!==-1&&!hasSpe){hasSpe=true;typesIncluded++;continue;}}result=Math.max(MIN_LENGTH-password.length,TYPES.length-typesIncluded);returnresult;}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Strong Password
You are viewing a single comment's thread. Return to all comments →
JavaScript