Skip to content

Commit 44ce568

Browse files
committed
adjusted Pr template
1 parent 94de70c commit 44ce568

File tree

3 files changed

+99
-1
lines changed

3 files changed

+99
-1
lines changed

Sprint-3/2-practice-tdd/count.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,4 @@ describe('countChar()', () => {
1919
expect(countChar('!!!', '!')).toBe(5);
2020
});
2121
});
22+
//this is the end.

Sprint-3/3-stretch/card-validator.md

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,64 @@ These are the requirements your project needs to fulfill:
3333
- Return a boolean from the function to indicate whether the credit card number is valid.
3434

3535
Good luck!
36+
37+
function validateCreditCard(number) {
38+
// Convert input to a string so we can check characters easily
39+
const numStr = String(number);
40+
41+
// Rule 1: Must be 16 digits, all numbers
42+
if (!/^\d{16}$/.test(numStr)) {
43+
return false;
44+
}
45+
46+
// Rule 2: Must contain at least two different digits
47+
const uniqueDigits = new Set(numStr);
48+
if (uniqueDigits.size < 2) {
49+
return false;
50+
}
51+
52+
// Rule 3: The last digit must be even
53+
const lastDigit = parseInt(numStr[numStr.length - 1]);
54+
if (lastDigit % 2 !== 0) {
55+
return false;
56+
}
57+
58+
// Rule 4: The sum of all digits must be greater than 16
59+
const sum = numStr
60+
.split("")
61+
.map(Number)
62+
.reduce((a, b) => a + b, 0);
63+
64+
if (sum <= 16) {
65+
return false;
66+
}
67+
68+
// If all checks pass, return true ✅
69+
return true;
70+
}
71+
72+
module.exports = validateCreditCard;
73+
74+
const validateCreditCard = require("./validateCreditCard");
75+
76+
test("valid credit card numbers should return true", () => {
77+
expect(validateCreditCard("9999777788880000")).toBe(true);
78+
expect(validateCreditCard("6666666666661666")).toBe(true);
79+
});
80+
81+
test("invalid cards with letters should return false", () => {
82+
expect(validateCreditCard("a92332119c011112")).toBe(false);
83+
});
84+
85+
test("invalid cards with all same digits should return false", () => {
86+
expect(validateCreditCard("4444444444444444")).toBe(false);
87+
});
88+
89+
test("invalid cards with sum less than 16 should return false", () => {
90+
expect(validateCreditCard("1111111111111110")).toBe(false);
91+
});
92+
93+
test("invalid cards with odd final digit should return false", () => {
94+
expect(validateCreditCard("6666666666666661")).toBe(false);
95+
});
96+

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

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,40 @@ function passwordValidator(password) {
33
}
44

55

6-
module.exports = passwordValidator;
6+
module.exports = passwordValidator;
7+
function validateCreditCard(number) {
8+
// Convert input to a string so we can check characters easily
9+
const numStr = String(number);
10+
11+
// Rule 1: Must be 16 digits, all numbers
12+
if (!/^\d{16}$/.test(numStr)) {
13+
return false;
14+
}
15+
16+
// Rule 2: Must contain at least two different digits
17+
const uniqueDigits = new Set(numStr);
18+
if (uniqueDigits.size < 2) {
19+
return false;
20+
}
21+
22+
// Rule 3: The last digit must be even
23+
const lastDigit = parseInt(numStr[numStr.length - 1]);
24+
if (lastDigit % 2 !== 0) {
25+
return false;
26+
}
27+
28+
// Rule 4: The sum of all digits must be greater than 16
29+
const sum = numStr
30+
.split("")
31+
.map(Number)
32+
.reduce((a, b) => a + b, 0);
33+
34+
if (sum <= 16) {
35+
return false;
36+
}
37+
38+
// If all checks pass, return true ✅
39+
return true;
40+
}
41+
42+
module.exports = validateCreditCard;

0 commit comments

Comments
 (0)