Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 0 additions & 35 deletions Sprint-3/3-stretch/card-validator.md

This file was deleted.

4 changes: 4 additions & 0 deletions Sprint-3/3-stretch/find.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ console.log(find("code your future", "z"));
// Pay particular attention to the following:

// a) How the index variable updates during the call to find
// In the beginning of the function it is set to 0, then each time the while loop runs it increases by 1 until it reaches the length of the string .
// b) What is the if statement used to check
// The if statement checks if the character at the current index of the string is equal to the character we are searching for. If it is, the function returns the current index.
// c) Why is index++ being used?
// The index++ is used to move to the next character in the string after each iteration of the while loop.
// d) What is the condition index < str.length used for?
// The condition index < str.length is used to ensure that the while loop continues to run as long as there are characters left to check in the string.
30 changes: 27 additions & 3 deletions Sprint-3/3-stretch/password-validator.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,30 @@
function passwordValidator(password) {
return password.length < 5 ? false : true
}
const passwords = ["Abcde1!", "Hello#2"];
function passwordValidator(password) {
if (password.length < 5) {
return false;
}

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;
}

if (passwords.includes(password)) {
return false;
}


return true;
}

module.exports = passwordValidator;
50 changes: 48 additions & 2 deletions Sprint-3/3-stretch/password-validator.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,52 @@ test("password has at least 5 characters", () => {
// Act
const result = isValidPassword(password);
// Assert
expect(result).toEqual(true);
expect(result).toEqual(false);
}
);
);

// passsword has at least one uppercase letter
test("password has at least one uppercase letter", () => {

const password = "1234a";
const result = isValidPassword(password);
expect(result).toEqual(false);
}
);

// password has at least one lowercase letter
test("password has at least one lowercase letter", () => {

const password = "1234A";
const result = isValidPassword(password);
expect(result).toEqual(false);
}
);

// password has at least one number
test("password has at least one number", () => {

const password = "abcdA";
const result = isValidPassword(password);
expect(result).toEqual(false);
}
);

// password has at least one symbol:
test("password has at least one symbol: (!, #, $, %, ., *, &)", () => {

const password = "abcdA1";
const result = isValidPassword(password);
expect(result).toEqual(false);
}
);

// password must not be any previous password in the passwords array.
test("password must not be any previous password in the passwords array.", () => {

const password = "abcde1!";
const result = isValidPassword(password);
expect(result).toEqual(false);
}
);