Skip to content

Conversation

@Tarawally
Copy link

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

Changelist

  • Implemented all solution functions in the implement folder.
  • Added tests for each function using assertions.
  • Rewrote all tests in Jest in the rewrite-tests-with-jest folder.
  • Covered all main and edge cases as required.

@Tarawally Tarawally added the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Nov 10, 2025
Comment on lines +14 to +15
const numValue = parseInt(rank);
if (numValue >= 2 && numValue <= 9) return numValue;
Copy link
Contributor

Choose a reason for hiding this comment

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

In JavaScript, strings that represent valid numeric literals in the language can be safely
converted to equivalent numbers or parsed into a valid integers.
Do you want to recognize these string values as valid ranks?

To find out what these strings are, you can ask AI

What kinds of string values would make parseInt(rank) evaluate to 2 in JS?

Copy link
Author

@Tarawally Tarawally Nov 13, 2025

Choose a reason for hiding this comment

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

My understanding is that the parseInt function converts a string to an integer by parsing its leading numerical characters:

parseInt(" 7abc")   // returns 7  

Given this, my current code would accept "03", for example, and this clearly isn't a valid rank. A better approach I think is to use a conditional statement which explicitly checks the rank against a limited set of numeric literals.

Is my understanding correct here, @cjyuan?

Copy link
Contributor

Choose a reason for hiding this comment

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

If we were to recognise only the 13 possible ranks, then a stricter check would be needed.

Can you figure out exactly how to implement them (as an exercise)?

Copy link
Author

Choose a reason for hiding this comment

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

Suggested change
const numValue = parseInt(rank);
if (numValue >= 2 && numValue <= 9) return numValue;
function getCardValue(card) {
const rank = card.slice(0, -1);
if (rank === "A") return 11;
if (rank === "J" || rank === "Q" || rank === "K") return 10;
const numRanks = ["2", "3", "4", "5", "6", "7", "8", "9", "10"];
if (numRanks.includes(rank)) {
return Number(rank);
}
throw new Error("Invalid card rank");
}

});

test("should return 10 for face cards (J, Q, K, 10)", () => {
expect(getCardValue("10♣")).toEqual(10);
Copy link
Contributor

Choose a reason for hiding this comment

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

I think 10 is considered a number card.

Copy link
Author

Choose a reason for hiding this comment

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

Yes, it is. I will update the test to count 10 as a number card and change the test descriptions to reflect this.

@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 Nov 11, 2025
@cjyuan
Copy link
Contributor

cjyuan commented Nov 15, 2025

Changes look good. Well done!

@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 Nov 15, 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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

02 Complete Sprint 3 implement and rewrite tests coursework

2 participants