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:number,password:string):number{/** * simple * 1. check [password] missing [x] in length * 2. check [password] missing [y] in types of character * 3. return the larger [x] or [y] * * why? * if you miss 3 length but miss 1 type, you can write that missing type * in 3 character missing length to satisfy both conditions. * if tou miss 1 length but miss 3 type, you need to type at least 3 character * in 3 type and that satisfy missing length condition too. */constcheck_miss_length=():number=>{if(n<6)return6-nreturn0}constcheck_miss_types=():number=>{consttype_digit=(/([\d])/.test(password))?0:1consttype_lower=(/([a-z])/.test(password))?0:1consttype_upper=(/([A-Z])/.test(password))?0:1consttype_speci=(/([^a-z0-9A-Z])/.test(password))?0:1returntype_digit+type_lower+type_upper+type_speci;}returnMath.max(check_miss_length(),check_miss_types())}
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 →
My answer in Typescript, simple, not minimized