Skip to content

London | 26-ITP-May | Russom Gebremeskel | Sprint 3 | Coursework Stretch - #1746

Open
russom-g wants to merge 84 commits into
CodeYourFuture:mainfrom
russom-g:coursework/sprint-3-stretch
Open

russom-g wants to merge 84 commits into
CodeYourFuture:mainfrom
russom-g:coursework/sprint-3-stretch

Conversation

@russom-g

Copy link
Copy Markdown

Learners, PR Template

Self checklist

  • I have titled my PR with Region | Cohort | FirstName LastName | Sprint | Assignment Title
  • My changes meet the requirements of the task
  • I have tested my changes
  • My changes follow the style guide

Task code

CYF-1065

Changelist

Password validator test written and function implemented. Questions answers and code explained

@russom-g russom-g added the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Oct 22, 2026

@cjyuan cjyuan left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not also try the card-validator exercise?

Comment thread sprint-3-stretch-exercises/find.js Outdated
// b) What is the if statement used to check
// - It checks whether the character at position index of str is exactly equal to char. If so it returns that position.
// c) Why is index++ being used?
// - index++ checks the next character of str. Without index would stay at 0 and the loop would never stop.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

index++ does not "check the next character str". Could you rephrase the statement?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

index++ increments by 1 each time the lope find a match?

@cjyuan cjyuan Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That still does not quite explain "why" it is being used in the code.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's used to move into the next character in str if a matching char is not found.

@cjyuan cjyuan added Reviewed Volunteer to add when completing a review with trainee action still to take. and removed Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. labels Oct 24, 2026
@russom-g

Copy link
Copy Markdown
Author

@cjyuan I didn't know there was another card-validator exercise. I will do it.

@russom-g russom-g added Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. and removed Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. labels Oct 27, 2026
@cjyuan cjyuan added Complete Volunteer to add when work is complete and all review comments have been addressed. Reviewed Volunteer to add when completing a review with trainee action still to take. and removed Reviewed Volunteer to add when completing a review with trainee action still to take. Complete Volunteer to add when work is complete and all review comments have been addressed. labels Oct 27, 2026
@russom-g

Copy link
Copy Markdown
Author

@cjyuan card-validator exercise is complete now.

Thanks for reminding me.

@russom-g russom-g added Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. and removed Reviewed Volunteer to add when completing a review with trainee action still to take. labels Oct 30, 2026
@@ -0,0 +1,29 @@
export function creditCardValidator(cardNumber) {
// rejects the number if itn's exactly 16 characters or contain non-digits
if (cardNumber.length !== 16 || !Number.isInteger(Number(cardNumber))) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any string resembling a valid number literal in JS could be safely converted to a number.

For examples, all these cases could pass the check.

creditCardValidator("3.14159265358e16");
creditCardValidator("+123456789012344");
creditCardValidator("             998");
creditCardValidator("0x1111aaaa000998");

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I deleted the !Number.isInteger(Number(cardNumber))) condition and replaced it with a condition that check cardNumber is between 0 and 9.

Comment on lines +56 to +61
test("password must not be any previous password in the passwords array", () => {
const password = "1Az9!";
const previousPassword = ["1Az9!", "1HBz2!"];
const result = isValidPassword(password, previousPassword);
expect(result).toEqual(false);
});

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In addition to testing if the function could return false when the given password match a previous password, we should also test if the function could return true when the given password does not match any previous password (when the array of previous passwords is provided).

We could include multiple expect() to test several cases within the same category.

To make the test even more comprehensive, we could also test if the function could work correctly when the matching previous password appears as the first/last element in the array.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test cases added when previous password doesn't match and when swapping previous password element position in the array.

@cjyuan cjyuan added Reviewed Volunteer to add when completing a review with trainee action still to take. and removed Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. labels Oct 30, 2026
@cjyuan

cjyuan commented Oct 30, 2026

Copy link
Copy Markdown
Contributor

Changes look good.

Feel free to use AI to explore different ways to check if all 16 characters are digits in JS.

@cjyuan cjyuan added Complete Volunteer to add when work is complete and all review comments have been addressed. and removed Reviewed Volunteer to add when completing a review with trainee action still to take. labels Oct 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Complete Volunteer to add when work is complete and all review comments have been addressed.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants