Skip to content

Commit 351cb9e

Browse files
committed
Stretch
1 parent 14d8bcb commit 351cb9e

File tree

3 files changed

+59
-3
lines changed

3 files changed

+59
-3
lines changed

Sprint-3/3-stretch/find.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ console.log(find("code your future", "z"));
2020
// Pay particular attention to the following:
2121

2222
// a) How the index variable updates during the call to find
23+
// it changes during each iteration of cycle. (index++)
2324
// b) What is the if statement used to check
25+
// in this example it check where is character in "str" and return its index.
2426
// c) Why is index++ being used?
27+
// to change index value during iteration
2528
// d) What is the condition index < str.length used for?
29+
// its a condition for while statement, cycle will repeat until statement is true

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

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,27 @@
11
function passwordValidator(password) {
2-
return password.length < 5 ? false : true
2+
//return password.length < 5 ? false : true
3+
const prevPasswords = ["Aa0Cc!ZzB#b91", "Aa0Cc!ZzB#b92","Aa0Cc!ZzB#b93"]
4+
let result = true
5+
if (password.length < 5){
6+
result = false
7+
}
8+
const hasUppercase = /[A-Z]/.test(password);
9+
const hasLowercase = /[a-z]/.test(password);
10+
if (!hasLowercase || !hasUppercase){
11+
result = false;
12+
}
13+
const hasNumber = /[0-9]/.test(password);
14+
if (!hasNumber){
15+
result = false
16+
}
17+
const hasSymbol =/[!#$%.*&]/.test(password);
18+
if (!hasSymbol){
19+
result = false
20+
}
21+
if (prevPasswords.includes(password)){
22+
result = false
23+
}
24+
return result
325
}
426

527

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

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,42 @@ 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-
test("password has at least 5 characters", () => {
18+
test("Password has at least 5 characters", () => {
1919
// Arrange
20-
const password = "12345";
20+
const password = "Cc#1";
2121
// Act
2222
const result = isValidPassword(password);
2323
// Assert
24+
expect(result).toEqual(false);
25+
}
26+
);
27+
test("Have at least one English uppercase letter (A-Z)", () => {
28+
const password = "AaBb5%Cc#11Zz";
29+
const result = isValidPassword(password);
30+
expect(result).toEqual(true);
31+
}
32+
);
33+
test("Have at least one English lowercase letter (a-z)", () => {
34+
const password = "AaBbCcZ2#z";
35+
const result = isValidPassword(password);
36+
expect(result).toEqual(true);
37+
}
38+
);
39+
test("Have at least one number (0-9)", () => {
40+
const password = "1Aa0CcZz!Bb9";
41+
const result = isValidPassword(password);
42+
expect(result).toEqual(true);
43+
}
44+
);
45+
test("Have at least one of the following non-alphanumeric symbols:", () => {
46+
const password = "Aa0Cc!ZzB#b9";
47+
const result = isValidPassword(password);
48+
expect(result).toEqual(true);
49+
}
50+
);
51+
test("Must not be any previous password in the passwords array.", () => {
52+
const password = "Aa0Cc!ZzB#b9";
53+
const result = isValidPassword(password);
2454
expect(result).toEqual(true);
2555
}
2656
);

0 commit comments

Comments
 (0)