Repository navigation
Conversation
This comment has been minimized.
This comment has been minimized.
cjyuan
left a comment
There was a problem hiding this comment.
Why not also try the card-validator exercise?
| for (const char of password) { | ||
| if (!/[A-Z]/.test(password)) return false; | ||
| if (!/[a-z]/.test(password)) return false; | ||
| if (!/[0-9]/.test(password)) return false; | ||
| if (!/[!#$%.*&]/.test(password)) return false; | ||
| } |
There was a problem hiding this comment.
Where is char (the loop variable) being used?
There was a problem hiding this comment.
It's a dead code that I forgot to delete from previous attempt to solve the problesm.
| test("password must not be any previous password in the passwords array", () => { | ||
| const password = "1Az9!"; | ||
| const previousPassword = ["1Az9!", "1HBz2!"]; | ||
| const result = isValidPassword(password, previousPassword); | ||
| expect(result).toEqual(false); | ||
| }); |
There was a problem hiding this comment.
Could the function return true if the valid password is not one of the previous passwords?
There was a problem hiding this comment.
Yes. I changed the test to (true) and it fails.
| // b) What is the if statement used to check | ||
| // - It checks whether the character at position index of str is exactly equal to char. If so it returns that position. | ||
| // c) Why is index++ being used? | ||
| // - index++ checks the next character of str. Without index would stay at 0 and the loop would never stop. |
There was a problem hiding this comment.
index++ does not "check the next character str". Could you rephrase the statement?
There was a problem hiding this comment.
index++ increments by 1 each time the lope find a match?
There was a problem hiding this comment.
That still does not quite explain "why" it is being used in the code.
|
@cjyuan I didn't know there was another card-validator exercise. I will do it. |
Learners, PR Template
Self checklist
Task code
CYF-1065
Changelist
Password validator test written and function implemented. Questions answers and code explained