Skip to content

Conversation

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

all tasks are done thank you very much

Questions

@HadiVahidi20 HadiVahidi20 added the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Oct 31, 2025
Comment on lines 2 to 11
const twoLastDig = num % 100;
if (twoLastDig === 11 || twoLastDig === 12 || twoLastDig === 13) {
return num + "th";
}

const lastDig = num % 10;
if (lastDig === 1) return num + "st";
if (lastDig === 2) return num + "nd";
if (lastDig === 3) return num + "rd";
return num + "th";
Copy link
Contributor

Choose a reason for hiding this comment

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

Keeping it or its in the variable names would probably make them more meaningful.

Comment on lines 14 to 43
test("should return '11th' for 11", () => {
expect(getOrdinalNumber(11)).toEqual("11th");
});

test("should return '2nd' for 2", () => {
expect(getOrdinalNumber(2)).toEqual("2nd");
});


test("should return '23rd' for 23rd", () => {
expect(getOrdinalNumber(23)).toEqual("23rd");
});
test("should return '3rd' for 3", () => {
expect(getOrdinalNumber(3)).toEqual("3rd");
});
test("should return '4th' for 4", () => {
expect(getOrdinalNumber(4)).toEqual("4th");
});

test("should return '12th' for 12", () => {
expect(getOrdinalNumber(12)).toEqual("12th");
});
test("should return '13th' for 13", () => {
expect(getOrdinalNumber(13)).toEqual("13th");
});


test("should return '101st' for 101", () => {
expect(getOrdinalNumber(101)).toEqual("101st");
});
Copy link
Contributor

Choose a reason for hiding this comment

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

To ensure thorough testing, we need broad scenarios that cover all possible cases.
Listing individual values, however, can quickly lead to an unmanageable number of test cases.
Instead of writing tests for individual numbers, consider grouping all possible input values into meaningful categories.
Then, select representative samples from each category to test. This approach improves coverage and makes our tests easier to maintain.

For example, we can prepare a test for numbers 2, 22, 132, etc. as

test("append 'nd' to numbers ending in 2, except those ending in 12", () => {
    expect( getOrdinalNumber(2) ).toEqual("2nd");
    expect( getOrdinalNumber(22) ).toEqual("22nd");
    expect( getOrdinalNumber(132) ).toEqual("132nd");
});

Comment on lines +5 to +7
if(count<0){
return "invalid"
}
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("invalid", 1)
  2. repeat("", -1)

Comment on lines 45 to 50
test("should repeat the string count times", () => {
const str = "hello";
const count = -1;
const repeatedStr = repeat(str, count);
expect(repeatedStr).toEqual("invalid");
});
Copy link
Contributor

Choose a reason for hiding this comment

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

If you modified repeat() to throw an error when count is negative, and you wanted to test if the function can throw an error as expected, you can use .toThrow(). You can find out more about how to use .toThrow() here: https://jestjs.io/docs/expect#tothrowerror (Note: Pay close attention to the syntax of the example)

@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 8, 2025
@HadiVahidi20
Copy link
Author

hi Cj
thank you very much for reviewing my PR, I tried to correct and update the code base on your comments.

@HadiVahidi20 HadiVahidi20 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 9, 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 changes made to the repeat() function and its tests look good.

Comment on lines 2 to 4
const itsTwoLastDigs = num % 100;
if (itsTwoLastDigs === 11 || itsTwoLastDigs === 12 || itsTwoLastDigs === 13) {
return num + "th";
Copy link
Contributor

Choose a reason for hiding this comment

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

How should its be included into twoLastDig to make the variable name more meaningful than itsTwoLastDigs?

Comment on lines 11 to 41
describe("getOrdinalNumber", () => {
test("append 'st' to numbers ending in 1 expect 11", () => {
expect(getOrdinalNumber(1)).toEqual("1st");
expect(getOrdinalNumber(101)).toEqual("101st");
});
test("should return '11th' for 11", () => {
expect(getOrdinalNumber(11)).toEqual("11th");
});

test("append 'rd' to numbers ending in 3", () => {
expect(getOrdinalNumber(3)).toEqual("3rd");
expect(getOrdinalNumber(23)).toEqual("23rd");
expect(getOrdinalNumber(33)).toEqual("33rd");
expect(getOrdinalNumber(103)).toEqual("103rd");
});
test("should return '4th' for 4", () => {
expect(getOrdinalNumber(4)).toEqual("4th");
});

test("should return '12th' for 12", () => {
expect(getOrdinalNumber(12)).toEqual("12th");
});
test("should return '13th' for 13", () => {
expect(getOrdinalNumber(13)).toEqual("13th");
});

test("append 'nd' to numbers ending in 2, except those ending in 12", () => {
expect(getOrdinalNumber(2)).toEqual("2nd");
expect(getOrdinalNumber(22)).toEqual("22nd");
expect(getOrdinalNumber(132)).toEqual("132nd");
});
Copy link
Contributor

Choose a reason for hiding this comment

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

  • These test categories have been improved but still not fully comprehensive; collectively they haven't yet covered all possible cases.

  • And you can consider merge some of these tests into one category.

Can you try to further improve them. Feel free to ask AI for some suggestions.

@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 9, 2025
Renamed variables for clarity and added more complete, grouped test cases
@HadiVahidi20
Copy link
Author

Thank you for your feedback! I have updated the variable names to make them clearer and also improved the test cases by adding more examples and grouping similar ones together.

1 similar comment
@HadiVahidi20
Copy link
Author

Thank you for your feedback! I have updated the variable names to make them clearer and also improved the test cases by adding more examples and grouping similar ones together.

@HadiVahidi20 HadiVahidi20 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 11, 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.

Changes look good.

Comment on lines 38 to 41
test("handles negative numbers", () => {
expect(getOrdinalNumber(-1)).toBe("-1st");
expect(getOrdinalNumber(-11)).toBe("-11th");
});
Copy link
Contributor

Choose a reason for hiding this comment

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

Did you prepare this test because the function is supposed to behave like that, or because your function is behaving like that?

@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 11, 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.

2 participants