From 3736064822d5a44f9429824b6f50a7257b06b0b5 Mon Sep 17 00:00:00 2001 From: UbunMen Date: Fri, 21 Nov 2025 14:04:47 +0000 Subject: [PATCH 1/4] Transferred only related files from old Stretch branch to new-fixed branch --- Sprint-3/3-stretch/find.js | 18 ++++++- Sprint-3/3-stretch/password-validator.js | 13 +++-- Sprint-3/3-stretch/password-validator.test.js | 49 ++++++++++++++++--- 3 files changed, 68 insertions(+), 12 deletions(-) diff --git a/Sprint-3/3-stretch/find.js b/Sprint-3/3-stretch/find.js index c7e79a2f2..e8ff08dc6 100644 --- a/Sprint-3/3-stretch/find.js +++ b/Sprint-3/3-stretch/find.js @@ -19,7 +19,23 @@ console.log(find("code your future", "z")); // Use the Python Visualiser to help you play computer with this example and observe how this code is executed // Pay particular attention to the following: -// a) How the index variable updates during the call to find +// a) How the index variable updates during the call to find a char + + // As the code runs, index starts from zero and runs until the length of the string, + // It starts from zero and in each loop it gets incremented until a char is found within the string. + // b) What is the if statement used to check + + // It checks if the char is in the string. If it exists.. next step is to return the index of the char. + + // c) Why is index++ being used? + + // To check if the given char is present starting from 0 till str.length. + + // d) What is the condition index < str.length used for? + + // As long as index is less than the length of the string, keep looping until the char is found. + +// Added explanation to the questions. \ No newline at end of file diff --git a/Sprint-3/3-stretch/password-validator.js b/Sprint-3/3-stretch/password-validator.js index b55d527db..74bd9e444 100644 --- a/Sprint-3/3-stretch/password-validator.js +++ b/Sprint-3/3-stretch/password-validator.js @@ -1,6 +1,13 @@ -function passwordValidator(password) { - return password.length < 5 ? false : true +function isValidPassword(password, previousPasswords = []) { + return ( + password.length >= 5 && + /[A-Z]/.test(password) && + /[a-z]/.test(password) && + /[0-9]/.test(password) && + /[!#$%.*&]/.test(password) && + !previousPasswords.includes(password) + ); } -module.exports = passwordValidator; \ No newline at end of file +module.exports = isValidPassword; \ No newline at end of file diff --git a/Sprint-3/3-stretch/password-validator.test.js b/Sprint-3/3-stretch/password-validator.test.js index 8fa3089d6..f2f946e83 100644 --- a/Sprint-3/3-stretch/password-validator.test.js +++ b/Sprint-3/3-stretch/password-validator.test.js @@ -15,12 +15,45 @@ To be valid, a password must: You must breakdown this problem in order to solve it. Find one test case first and get that working */ const isValidPassword = require("./password-validator"); +const previousPasswords = ["Mmd1!", "XyZ2$", "Tes5%"]; + + test("password has at least 5 characters", () => { - // Arrange - const password = "12345"; - // Act - const result = isValidPassword(password); - // Assert - expect(result).toEqual(true); -} -); \ No newline at end of file + const password = "Ki55$"; + const result = isValidPassword(password, previousPasswords); // pass the array + expect(result).toEqual(true); +}); + +test("password has at least one uppercase", () => { + const password = "Uo85*"; + const result = isValidPassword(password, previousPasswords); + expect(result).toEqual(true);npx +}); + +test("password has at least one lowercase", () => { + const password = "Qf#45"; + const result = isValidPassword(password, previousPasswords); + expect(result).toEqual(true); +}); + +test("password has at least one number", () => { + const password = "Cz!35"; + const result = isValidPassword(password, previousPasswords); + expect(result).toEqual(true); +}); + +test("password has at least one special symbol", () => { + const password = "Re*19"; + const result = isValidPassword(password, previousPasswords); + expect(result).toEqual(true); +}); + +test("password must not be a previous password", () => { + const password = "Mmd1!"; + const result = isValidPassword(password, previousPasswords); + expect(result).toEqual(false); + +}); + + +// Password-validator implemented and tested. From cfa4ac50b8572f0e5a8bc0be84dff22bf2c1704a Mon Sep 17 00:00:00 2001 From: UbunMen Date: Fri, 21 Nov 2025 14:08:13 +0000 Subject: [PATCH 2/4] In find.js explanations given to the question. --- Sprint-3/3-stretch/find.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sprint-3/3-stretch/find.js b/Sprint-3/3-stretch/find.js index e8ff08dc6..f309177f5 100644 --- a/Sprint-3/3-stretch/find.js +++ b/Sprint-3/3-stretch/find.js @@ -38,4 +38,4 @@ console.log(find("code your future", "z")); // As long as index is less than the length of the string, keep looping until the char is found. -// Added explanation to the questions. \ No newline at end of file +// In find.js explanations given to the question. \ No newline at end of file From 943def1044d001333ddbb4f165b699fcb03155e8 Mon Sep 17 00:00:00 2001 From: UbunMen Date: Fri, 21 Nov 2025 14:09:19 +0000 Subject: [PATCH 3/4] In password-validator.js function implemented. --- Sprint-3/3-stretch/password-validator.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Sprint-3/3-stretch/password-validator.js b/Sprint-3/3-stretch/password-validator.js index 74bd9e444..d3fa0e12e 100644 --- a/Sprint-3/3-stretch/password-validator.js +++ b/Sprint-3/3-stretch/password-validator.js @@ -10,4 +10,6 @@ function isValidPassword(password, previousPasswords = []) { } -module.exports = isValidPassword; \ No newline at end of file +module.exports = isValidPassword; + +// In password-validator.js function implemented. \ No newline at end of file From ec2520aee0c047ce5636b6dd7bf8757f8065ea49 Mon Sep 17 00:00:00 2001 From: UbunMen Date: Fri, 21 Nov 2025 14:10:10 +0000 Subject: [PATCH 4/4] In Password-validator.test.js cases tested and passed. --- Sprint-3/3-stretch/password-validator.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sprint-3/3-stretch/password-validator.test.js b/Sprint-3/3-stretch/password-validator.test.js index f2f946e83..829b592d2 100644 --- a/Sprint-3/3-stretch/password-validator.test.js +++ b/Sprint-3/3-stretch/password-validator.test.js @@ -56,4 +56,4 @@ test("password must not be a previous password", () => { }); -// Password-validator implemented and tested. +// In Password-validator.test.js cases tested and passed.