Modo entrevista. Temporizador de 5 min, sin pistas y sin autocompletado
Password length from 20 to 40
FácilBasics5 min
Write a function isValidPassword(password) that checks the length of a password. The parameter password is a string.
- Return
trueif the password has from 20 to 40 characters. Both 20 and 40 are valid. - Return
falseif it has fewer than 20 or more than 40 characters. The empty string''has 0 characters, so it is not valid. - Every character counts, spaces too, also at the start and at the end. Do not remove anything.
- Only the length matters, not which characters are used.
The result is a boolean: true or false. The passwords in the tests have only simple characters: letters, digits, spaces and signs like !.
Ejemplos
isValidPassword('MySecretPassword2024')Devuelve true
isValidPassword('qwerty')Devuelve false
isValidPassword(' my long password ')Devuelve true
Preguntada en EPAM · Fuente
Cargando el editor…
- Entrada
isValidPassword('MySecretPassword2024')Esperadotrue - Entrada
isValidPassword('correct horse battery staple')Esperadotrue - Entrada
isValidPassword('qwerty')Esperadofalse - Entrada
isValidPassword('this password is way too long to be accepted')Esperadofalse - Entrada
isValidPassword('my-password.is_long, ok?')Esperadotrue
Las pruebas ocultas se ejecutan al enviar