Skip to content

Conversation

@ahmadehsas
Copy link

@ahmadehsas ahmadehsas commented Oct 5, 2025

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:

I have completed all the mandatory tasks. The changes I have made in the files are as below:

  • Sprint-3/1-key-implement
  • Sprint-3/2-mandatory-rewrite
  • Sprint-3/3-mandatory-practice

Questions

…he goal of this function is to count how many times a specific character appears in a given string
@github-actions
Copy link

github-actions bot commented Oct 5, 2025

Your PR description contained template fields which weren't filled in.

Check you've ticked everything in the self checklist, and that any sections which prompt you to fill in an answer are either filled in or removed.

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).

@cjyuan cjyuan added the Reviewed Volunteer to add when completing a review with trainee action still to take. label Oct 30, 2025
@ahmadehsas
Copy link
Author

ahmadehsas commented Oct 30, 2025 via email

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

cjyuan commented Oct 31, 2025

Thank you for your reviewing. I just have a question, should I make another
branch for ‘practice-tdd’ backlog or do that in the same branch?

Either way works.

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.

  • Good job in fixing the branch.

Comment on lines 11 to 17
if (Math.abs(numerator) < denominator) return true; // This version of code works correctly for proper and negative fractions.
if (Math.abs(numerator) >= Math.abs(denominator)) return false;
if (Math.abs(numerator) === Math.abs(denominator)) return false;

if (numerator < denominator) {
return true;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

  • What do you expect from isProperFraction(-2, -3)?

  • Some of the code is redundant.

Copy link
Author

Choose a reason for hiding this comment

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

  • My expectation for 'isProperFraction (-2, -3) ': the fraction is proper because the absolute value of -2 / -3 is 2 / 3 and the numerator is less than the denominator, so the return should be true.
  • The redundant code has been removed.

Comment on lines 13 to 15
if (!isNaN(rank)) {
return Number(rank); // Number card
}
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. For examples, "0x02", "2.1", "9e1" or "0002"

Do you want to recognize these string values as valid ranks?

Copy link
Author

Choose a reason for hiding this comment

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

To recognise string values as valid ranks, I used 'Number(rank)'
console.log(Number("0x002"));
console.log(Number("2.1"));
console.log(Number("9e1"));
console.log(Number("0002"));

Comment on lines 16 to 20
test("should return true for negative fractions", () => {
const negativeFraction = isProperFraction(-4, 7);
expect(negativeFraction).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.

Not all negative fractions are proper fractions. For example, -5/2.

If you allow negative denominator, then you could also test isProperFraction(4, -7), isProperFraction(-4, -7), isProperFraction(-7, 4), isProperFraction(-7, -4), isProperFraction(7, -4).

Copy link
Author

Choose a reason for hiding this comment

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

I employed 'Math.abs(denominator)' to handle fractions with negative denominators.

Copy link
Contributor

Choose a reason for hiding this comment

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

The function is correct. I was referring to test and the test description.
The test description, "should return true for negative fractions", is misleading because negative fractions can be proper or improper.

Comment on lines 29 to 52
test("throws an error or invalid card", () => {
expect(() => getCardValue("Z♠")).toThrow("Invalid card");
});

test("should throw error for malformed numeric input", () => {
expect(() => getCardValue("2.9999♠")).toThrow("Invalid card rank");
});

test("should throw error for repeated characters in rank", () => {
expect(() => getCardValue("3AAAA♠")).toThrow("Invalid card rank");
});

test("should throw error for number beyond valid range", () => {
expect(() => getCardValue("11♠")).toThrow("Invalid card rank");
});

test("should throw error for missing suit", () => {
expect(() => getCardValue("Q")).toThrow("Invalid card rank");
});

test("should throw error for non-string input", () => {
expect(() => getCardValue(5)).toThrow("Card must be a string");
});

Copy link
Contributor

Choose a reason for hiding this comment

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

  • Can you current implementation pass all these tests?

  • Why specifically test "repeated characters" in rank? What's so special about this particular string pattern?

  • "2.9999" is not really a malformed numeric value.

  • The function is not expected to check the suit character. Including a test for missing suit might send the wrong message to the person implementing the function.

Copy link
Contributor

Choose a reason for hiding this comment

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

Why specifically test "repeated characters" in rank? What's so special about this particular string pattern?

test("should throw error for repeated characters in rank", () => {
  expect(() => getCardValue("3AAAA♠")).toThrow("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.

image

The subfolder containing these two files were moved from its original folder.

@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 31, 2025
@ahmadehsas ahmadehsas 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 Nov 3, 2025
Comment on lines 11 to 13
if (Math.abs(numerator) < Math.abs(denominator)) return true; // This version of code works correctly for proper and negative fractions.
if (Math.abs(numerator) >= Math.abs(denominator)) return false;
if (Math.abs(numerator) === Math.abs(denominator)) return false;
Copy link
Contributor

Choose a reason for hiding this comment

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

  • Some of these code will never get executed.

  • If the condition of the if statements are opposite of each other, we could use if-else.

Comment on lines 43 to 45
if (!/^[0-9]+$/.test(rank)) {
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.

This is a stricter check. Still, any string containing only digits could pass this test. For example, "0000002".

Comment on lines 16 to 20
test("should return true for negative fractions", () => {
const negativeFraction = isProperFraction(-4, 7);
expect(negativeFraction).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.

The function is correct. I was referring to test and the test description.
The test description, "should return true for negative fractions", is misleading because negative fractions can be proper or improper.

Comment on lines 29 to 52
test("throws an error or invalid card", () => {
expect(() => getCardValue("Z♠")).toThrow("Invalid card");
});

test("should throw error for malformed numeric input", () => {
expect(() => getCardValue("2.9999♠")).toThrow("Invalid card rank");
});

test("should throw error for repeated characters in rank", () => {
expect(() => getCardValue("3AAAA♠")).toThrow("Invalid card rank");
});

test("should throw error for number beyond valid range", () => {
expect(() => getCardValue("11♠")).toThrow("Invalid card rank");
});

test("should throw error for missing suit", () => {
expect(() => getCardValue("Q")).toThrow("Invalid card rank");
});

test("should throw error for non-string input", () => {
expect(() => getCardValue(5)).toThrow("Card must be a string");
});

Copy link
Contributor

Choose a reason for hiding this comment

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

Why specifically test "repeated characters" in rank? What's so special about this particular string pattern?

test("should throw error for repeated characters in rank", () => {
  expect(() => getCardValue("3AAAA♠")).toThrow("Invalid card rank");
});

@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 5, 2025
@ahmadehsas ahmadehsas 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 Nov 5, 2025


// Anything else is invalid
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.

Can you figure out why this statement will never get executed?

Comment on lines 15 to +20
// Case 3: Identify Negative Fractions:
test("should return true when the absolute value of numerator is less than denominator, even if the fraction is negative", () => {
const negativeFraction = isProperFraction(-4, 7);
expect(negativeFraction).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.

Instead of just testing one particular form of negative fraction, we could also test (under the same category)

 isProperFraction(4, -7);
 isProperFraction(-4, -7);
 isProperFraction(7, -4); 
 ... 

to make the test more complete.

Comment on lines +49 to +54
try {
getCardValue("Z♠");
} catch (error) {
console.log("Caught error:", error.message);
}

Copy link
Contributor

Choose a reason for hiding this comment

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

Debugging code?

@cjyuan cjyuan added Complete Volunteer to add when work is complete and all review comments have been addressed. and removed Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. labels Nov 6, 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.

3 participants