Skip to content

LONDON-JAN-25 | ANDREI FILIPPOV | Module-Structuring-and-Testing-Data | WEEK 3#309

Closed
Droid-An wants to merge 12 commits intoCodeYourFuture:mainfrom
Droid-An:coursework/sprint-3
Closed

LONDON-JAN-25 | ANDREI FILIPPOV | Module-Structuring-and-Testing-Data | WEEK 3#309
Droid-An wants to merge 12 commits intoCodeYourFuture:mainfrom
Droid-An:coursework/sprint-3

Conversation

@Droid-An
Copy link

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

Complete Sprint 3 coursework

Questions

no questions

@Droid-An Droid-An added the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Feb 20, 2025
@ChrisCookOC ChrisCookOC added Review in progress This review is currently being reviewed. This label will be replaced by "Reviewed" soon. and removed Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. labels Mar 5, 2025
Copy link

@ChrisCookOC ChrisCookOC left a comment

Choose a reason for hiding this comment

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

You've made good progress here, seems you are getting the hang of unit testing and using jest which is great to see :)


function isProperFraction(numerator, denominator) {
if (numerator < denominator) return true;
if (Math.abs(numerator) < Math.abs(denominator)) return true;

Choose a reason for hiding this comment

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

This all works, using the if / else if / else if.
However, a nice thing here is that your return values are booleans, which means you should be able to simplify this down into just two checks

Can you see a way of rewriting this in a simpler manner?

Can give a hint if needed! :)

Copy link
Author

Choose a reason for hiding this comment

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

Oh, now I see how I can simplify that. I just removed last two conditions which are unnecessary

Choose a reason for hiding this comment

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

Yep exactly :)

// Stretch:
// What other scenarios could you test for?

const improperNegativeFraction = isProperFraction(-5, 2);

Choose a reason for hiding this comment

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

Good scenario to test for!

// When the function is called with such a card,
// Then it should return the numeric value corresponding to the rank (e.g., "5" should return 5).
const fiveofHearts = getCardValue("5♥");
const fiveOfHearts = getCardValue("2♥");

Choose a reason for hiding this comment

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

I assume this comes from changing it to different values to test it is working, which is a great thing to do.

Just be careful when you are committing because the name of the variable is now misleading!

Copy link
Author

Choose a reason for hiding this comment

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

Yes, you're right. I was just short on time to check the correct names for the card values. I've updated it now.

if (rank === "A") return 11;
else if (rank === "J" || rank === "Q" || rank === "K") return 10;
else if (
typeof Number(rank) == "number" &&

Choose a reason for hiding this comment

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

This works, but are you able to find any functions you can call that check if something is a number instead? If they exist it is often best to use them and avoid having to code type checks like this!

Copy link
Author

Choose a reason for hiding this comment

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

Yes, I found the isNaN function, which seems to do exactly that.

// Given a card with an invalid rank (neither a number nor a recognized face card),
// When the function is called with such a card,
// Then it should throw an error indicating "Invalid card rank."
const invalid = getCardValue("five of hearts");

Choose a reason for hiding this comment

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

What should happens if I give you the input of "5.123♥"? Is that reflected in the program?

Copy link
Author

Choose a reason for hiding this comment

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

Thank you for pointing this out! I hadn’t considered that case. I resolved it by adding an isInteger condition.

function getOrdinalNumber(num) {
return "1st";
numToString = String(num);
if (numToString[numToString.length - 1] == 1 && num != 11) {

Choose a reason for hiding this comment

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

You repeat this multiple times
numToString[numToString.length - 1]

Can you see the benefits of doing this array access only once? if so, how would you do it?

Copy link
Author

Choose a reason for hiding this comment

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

Yes, I can assign that value to the lastDigit variable and use that variable throughout the code.

@ChrisCookOC ChrisCookOC added Reviewed Volunteer to add when completing a review with trainee action still to take. and removed Review in progress This review is currently being reviewed. This label will be replaced by "Reviewed" soon. labels Mar 5, 2025
@Droid-An Droid-An 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 Mar 5, 2025
@Droid-An Droid-An requested a review from ChrisCookOC March 5, 2025 22:26
Copy link

@ChrisCookOC ChrisCookOC left a comment

Choose a reason for hiding this comment

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

Thanks for taking the time to make some more changes :) Looks good.

else if (rank === "J" || rank === "Q" || rank === "K") return 10;
else if (
!isNaN(rank) &&
Number.isInteger(+(rank)) &&

Choose a reason for hiding this comment

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

Nice finds. Something you might be able to play with if you have time. Do you need both checks? Trial and error and find out :)

Copy link
Author

Choose a reason for hiding this comment

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

Oh, thank you for the remark. Testing showed that !isNaN is not necessary here.
Article about isInteger on MDN says:

If the value is NaN, return false.

So isInteger do job of both checks.

@ChrisCookOC ChrisCookOC 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 Mar 7, 2025
@Droid-An Droid-An added the Complete Volunteer to add when work is complete and all review comments have been addressed. label Mar 8, 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