Skip to content

Commit 3736064

Browse files
committed
Transferred only related files from old Stretch branch to new-fixed branch
1 parent 8f3d6cf commit 3736064

File tree

3 files changed

+68
-12
lines changed

3 files changed

+68
-12
lines changed

Sprint-3/3-stretch/find.js

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,23 @@ console.log(find("code your future", "z"));
1919
// Use the Python Visualiser to help you play computer with this example and observe how this code is executed
2020
// Pay particular attention to the following:
2121

22-
// a) How the index variable updates during the call to find
22+
// a) How the index variable updates during the call to find a char
23+
24+
// As the code runs, index starts from zero and runs until the length of the string,
25+
// It starts from zero and in each loop it gets incremented until a char is found within the string.
26+
2327
// b) What is the if statement used to check
28+
29+
// It checks if the char is in the string. If it exists.. next step is to return the index of the char.
30+
31+
2432
// c) Why is index++ being used?
33+
34+
// To check if the given char is present starting from 0 till str.length.
35+
36+
2537
// d) What is the condition index < str.length used for?
38+
39+
// As long as index is less than the length of the string, keep looping until the char is found.
40+
41+
// Added explanation to the questions.
Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
1-
function passwordValidator(password) {
2-
return password.length < 5 ? false : true
1+
function isValidPassword(password, previousPasswords = []) {
2+
return (
3+
password.length >= 5 &&
4+
/[A-Z]/.test(password) &&
5+
/[a-z]/.test(password) &&
6+
/[0-9]/.test(password) &&
7+
/[!#$%.*&]/.test(password) &&
8+
!previousPasswords.includes(password)
9+
);
310
}
411

512

6-
module.exports = passwordValidator;
13+
module.exports = isValidPassword;

Sprint-3/3-stretch/password-validator.test.js

Lines changed: 41 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,45 @@ To be valid, a password must:
1515
You must breakdown this problem in order to solve it. Find one test case first and get that working
1616
*/
1717
const isValidPassword = require("./password-validator");
18+
const previousPasswords = ["Mmd1!", "XyZ2$", "Tes5%"];
19+
20+
1821
test("password has at least 5 characters", () => {
19-
// Arrange
20-
const password = "12345";
21-
// Act
22-
const result = isValidPassword(password);
23-
// Assert
24-
expect(result).toEqual(true);
25-
}
26-
);
22+
const password = "Ki55$";
23+
const result = isValidPassword(password, previousPasswords); // pass the array
24+
expect(result).toEqual(true);
25+
});
26+
27+
test("password has at least one uppercase", () => {
28+
const password = "Uo85*";
29+
const result = isValidPassword(password, previousPasswords);
30+
expect(result).toEqual(true);npx
31+
});
32+
33+
test("password has at least one lowercase", () => {
34+
const password = "Qf#45";
35+
const result = isValidPassword(password, previousPasswords);
36+
expect(result).toEqual(true);
37+
});
38+
39+
test("password has at least one number", () => {
40+
const password = "Cz!35";
41+
const result = isValidPassword(password, previousPasswords);
42+
expect(result).toEqual(true);
43+
});
44+
45+
test("password has at least one special symbol", () => {
46+
const password = "Re*19";
47+
const result = isValidPassword(password, previousPasswords);
48+
expect(result).toEqual(true);
49+
});
50+
51+
test("password must not be a previous password", () => {
52+
const password = "Mmd1!";
53+
const result = isValidPassword(password, previousPasswords);
54+
expect(result).toEqual(false);
55+
56+
});
57+
58+
59+
// Password-validator implemented and tested.

0 commit comments

Comments
 (0)