Skip to content

Conversation

@asaniDev
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

created functions and practiced test driven development by making tests for the functions.

@github-actions
Copy link

Your PR's title isn't in the expected format.

Please check the expected title format, and update yours to match.

Reason: Sprint part (Sprint-3) doesn't match expected format (example: 'Sprint 2', without quotes)

If this PR is not coursework, please add the NotCoursework label (and message on Slack in #cyf-curriculum or it will probably not be noticed).

@asaniDev asaniDev changed the title West Midlands | ITP-Sept-25 | Mustaf Asani | Sprint-3 | Coursework/sprint 3 implement and rewrite West Midlands | ITP-Sept-25 | Mustaf Asani | Sprint 3 | Coursework/sprint 3 implement and rewrite Oct 23, 2025
@asaniDev asaniDev added the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Oct 23, 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.

The files in the Sprint-2 folder are not related to Sprint-3 exercise. Can you revert the changes made in the Sprint-2 folder?

// write one test at a time, and make it pass, build your solution up methodically

function isProperFraction(numerator, denominator) {
if (Math.sign(numerator) === -1 || Math.sign(denominator) === -1) {
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 an easier syntax to check if a number is negative.

  • And since you are using Math.abs(), checking for negatives is optional.

  • This function can be further simplified. If you are up to the challenge, go for a solution that uses at most one if-statement.

Copy link
Author

Choose a reason for hiding this comment

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

removed the check for negative and took off the first if else block, not quite sure how to reduce it to one if statement without making risky assumptions. since the function only returns true for a proper fraction and false for everything else, would it be appropriate to have an if statement that checks for a proper fraction and else that gives false for any other scenario?

// just make one change at a time -- don't rush -- programmers are deep and careful thinkers
function getCardValue(card) {
if (rank === "A") {
const rank = card[0];
Copy link
Contributor

@cjyuan cjyuan Oct 27, 2025

Choose a reason for hiding this comment

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

card[0] yields only a string with the first character -- not necessary the whole rank.

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 do need to make my tests more robust. I managed to get the correct rank for single digit and multiple digit cards.

Comment on lines 15 to 17
} else if (Number(rank) > 1 && Number(rank) < 10) {
return Number(rank);
} else if (rank === "10" || rank === "J" || rank === "Q" || rank === "K") {
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("10♠");
getCardValue("100♠");
getCardValue("3.1416♠");

Copy link
Author

Choose a reason for hiding this comment

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

the last function with 3.1416 showed that my condition for number cards was not checking that we have only a positive integer. I added an extra rule to check for an integer that way any decimal vlues will be flagged as invalid.

Comment on lines 15 to 17
test("should return true for a proper fraction based on the absolute values of the numerator and denominator", () => {
expect(isProperFraction(-3, 8)).toEqual(true);
});
Copy link
Contributor

Choose a reason for hiding this comment

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

To make the test more comprehensive, we could test multiple samples like this:

test("should return true for a proper fraction based on the absolute values of the numerator and denominator", () => {
  expect(isProperFraction(-3, 8)).toEqual(true);
  expect(isProperFraction(-3, -8)).toEqual(true);
  expect(isProperFraction(3, -8)).toEqual(true);
  expect(isProperFraction(3, 8)).toEqual(true);      
})

Copy link
Author

Choose a reason for hiding this comment

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

added multiple test samples for this and other lines as well.

Comment on lines 26 to 29
test("should return 11 for Ace of Spades", () => {
const invalidCard = getCardValue("1♥");
expect(invalidCard).toEqual("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.

The test description does not quite match what is being tested.

Copy link
Author

Choose a reason for hiding this comment

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

corrected the test description.

Comment on lines 11 to 14
test("should return a number matchig the rank value for given card", () => {
const numberCard = getCardValue("5♠");
expect(numberCard).toEqual(5);
});
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 "... for number cards (2-10)" would be more informative than "... for given card")
  • Could test multiple values, especially the boundary cases like "2♠" and "10♠".

Copy link
Author

Choose a reason for hiding this comment

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

added a more informative description. also tested the edge cases.

@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 27, 2025
…orrected test description for invalid cards, used more informative descriptions
… for cards with more than 1 digit, removed check for negative value since im using maths.abs
@asaniDev asaniDev added the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Oct 29, 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.

There are still three modified files in the "Sprint-2" folder. Can you revert the changes made to them?

Comment on lines 11 to 18
if (Math.abs(numerator) < Math.abs(denominator)) {
return true;
} else if (numerator > denominator) {
return false;
} else if (numerator === denominator) {
return false;
} else if (numerator === 0) {
return false;
Copy link
Contributor

@cjyuan cjyuan Oct 29, 2025

Choose a reason for hiding this comment

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

This is a good opportunities to practice code tracing -- to evaluate how the code get executed step by step using some sample pairs of parameter values. For examples,

  • -1, 2
  • 1, 2
  • 1, 0
  • 1, 1
  • 0, 1

Hopefully you can figure out why some of your code is not needed.

Comment on lines 11 to 15
let rank = "";

if (card === "A♠") {
return 11;
} else if (Number(rank) > 1 && Number(rank) < 10) {
for (let i = 0; i < card.length - 1; i++) {
rank += card[i];
}
Copy link
Contributor

Choose a reason for hiding this comment

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

This approach work.

You could also consider using built-in functions (methods) of String. Mastering these String's methods can simplify a lot of string processing tasks.

Comment on lines 17 to 18
if (Number.isInteger(Number(rank)) && Number(rank) > 1 && Number(rank) < 10) {
return Number(rank);
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 Number(rank) evaluate to 2 in JS?

Comment on lines 11 to 12
expect(isProperFraction(7, 4)).toEqual(false);
expect(isProperFraction(35, 8)).toEqual(false);
Copy link
Contributor

Choose a reason for hiding this comment

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

Could also test some negative improper fractions in this test.

Comment on lines 11 to 12
test("should return 10 for Face Cards", () => {
const faceCard = getCardValue("K♠");
const faceCard = getCardValue("10♠");
Copy link
Contributor

Choose a reason for hiding this comment

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

Face cards are J, Q, K. 10 is consider a number card.

Comment on lines 7 to 8
const numberCard = getCardValue("5♠");
expect(numberCard).toEqual(5);
Copy link
Contributor

Choose a reason for hiding this comment

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

We could test multiple samples (especially the boundary cases, "2♠" and "10♠") to make the test more robust.

Comment on lines 21 to 29
test("should return invalid card rank for cards that are not in the suite", () => {
const invalidCard = getCardValue("100♥");
expect(invalidCard).toEqual("Invalid card rank.");
});

test("should return invalid card rank for cards that are not in the suite", () => {
const invalidCard = getCardValue("3.1416♥");
expect(invalidCard).toEqual("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.

They both test "invalid case". Consider combine them into one test but using multiple samples.

@cjyuan cjyuan removed the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Oct 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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.

2 participants