Skip to content

Conversation

@AmirhosseinAminian
Copy link

@AmirhosseinAminian AmirhosseinAminian commented Feb 21, 2025

Learners, PR Template

Self checklist

  • I have committed my files one by one, on purpose, and for a reason
  • I have titled my PR with COHORT_NAME | FIRST_NAME LAST_NAME | REPO_NAME | WEEK
  • I have tested my changes
  • My changes follow the style guide
  • My changes meet the requirements of this task

Changelist

Briefly explain your PR.

Questions

Ask any questions you have for your reviewer.

@AmirhosseinAminian AmirhosseinAminian changed the title Sprint3/AmirAminian LON | Amirhossein Aminian | Module Stracturing and Testing Data | Sprint 3 Feb 21, 2025
@AmirhosseinAminian AmirhosseinAminian added the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Feb 21, 2025
@cjyuan cjyuan added the Review in progress This review is currently being reviewed. This label will be replaced by "Reviewed" soon. label Mar 2, 2025
Copy link
Contributor

@cjyuan cjyuan left a comment

Choose a reason for hiding this comment

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

Some files contain multiple implementations of the same function; you should delete or comment out those that you are not using.

There are some bugs in your code. Hope my comments and suggestions can help you fix them.

Copy link
Contributor

Choose a reason for hiding this comment

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

Why are there multiple implementations of isProperFraction()? Which one is the finalised one?

Comment on lines 8 to 10
if (denominator === 0) {
return "Undefined";
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Why return a string when denominator is 0? Can you think of a more appropriate value to return or another approach to report the denominator is 0?



// Case 3: Improper fraction (absolute numerator >= absolute denominator)
if (Math.abs(numerator) >= Math.abs(denominator)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

There is room to simplify the code in this function.
This is because when both parameters are numbers, by the time the execution reaches line 15, the condition will always be true.

}

// Case 5: Handle Invalid Cards
return null; // Invalid card returns null
Copy link
Contributor

Choose a reason for hiding this comment

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

It is a better practice to design a function that returns only one type of value.

Comment on lines 77 to 90
function getCardValue(card) {
const rank = card[0];
if (rank === "A") return 11;

if (parseInt(rank) >= 2 && parseInt(rank) <= 9) {
return parseInt(rank);
}

if (rank === "J" || rank === "Q" || rank === "K") {
return 10;
}

throw new Error("Invalid card rank.");
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Does your function return the value you expected from each of the following function calls?

getCardValue("AA♠");
getCardValue("10♠");
getCardValue("QQ♠");
getCardValue("2.1♠");

Comment on lines +3 to +9
if (typeof str !== "string" || typeof count !== "number") {
return "Invalid input";
}
if (count < 0) {
return "Count cannot be negative";
}
return str.repeat(count);
Copy link
Contributor

Choose a reason for hiding this comment

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

How would the caller distinguish the result of the following two function calls?

  1. repeat("Count cannot be negative", 1)
  2. repeat("", -1)

Both function calls return the same value.

Same goes for

  1. repeat("Invalid input", 1)
  2. repeat("", "")

Can you think of a better way to indicate error?

Comment on lines 3 to 9
test("valid credit card number", () => {
const cardNumber = "9999777788880000";
const result = isValidCreditCard(cardNumber);
expect(result).toBe(true);
});

test("credit card with only one digit type", () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Could include "Expect false when" in the description to make it clearer.

Comment on lines 33 to 37
test("credit card with multiple digit types", () => {
const cardNumber = "6666666666661666";
const result = isValidCreditCard(cardNumber);
expect(result).toBe(true);
});
Copy link
Contributor

Choose a reason for hiding this comment

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

How is this test different from the test specified in lines 3-7?

@@ -1,6 +1,25 @@
const passwords = ["previousPassword1", "anotherOldPassword"];
Copy link
Contributor

Choose a reason for hiding this comment

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

Would be better to specify valid passwords here so that when passwordValidator("previousPassword1") returns false, you can be certain it is not because the password is missing a special symbol.

Comment on lines 25 to 29
test("password contains at least one uppercase letter", () => {
const password = "123A5"; // Contains uppercase "A"
const result = passwordValidator(password);
expect(result).toBe(true);
});
Copy link
Contributor

Choose a reason for hiding this comment

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

Is "123A5" a valid password?
Should passwordValidator("123A5") return true?

@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. Review in progress This review is currently being reviewed. This label will be replaced by "Reviewed" soon. labels Mar 2, 2025
@AmirhosseinAminian
Copy link
Author

Good morning @cjyuan, thank you for your valuable tips and for helping me improve my code!

@AmirhosseinAminian AmirhosseinAminian added the Complete Volunteer to add when work is complete and all review comments have been addressed. label Mar 3, 2025
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. Reviewed Volunteer to add when completing a review with trainee action still to take.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants