Skip to content

Conversation

AdnaanA
Copy link

@AdnaanA AdnaanA commented Sep 29, 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

fixed test-case functions and created varies test cases to make sure the testcase function works correctly and passes all test case scenarios.

@AdnaanA AdnaanA added Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. 📅 Sprint 3 Assigned during Sprint 3 of this module labels Sep 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 also some exercises in Sprint-3/1-implement-and-rewrite-tests/.

function getOrdinalNumber(num) {
return "1st";

if (typeof num !== "number" || !Number.isInteger(num) || num <= 0) {
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 think of a more concise way to express the condition of this 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.

Hello,

Thank you for the feedback.

Yes the If statement can be made more concise. Here’s a more compact version:

if (!Number.isInteger(num) || num <= 0) {

Comment on lines 6 to 8
if (num % 100 >= 11 && num % 100 <= 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.

Indentation is a bit off.

Copy link
Author

Choose a reason for hiding this comment

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

Indentation is now fixed

Comment on lines 55 to 61
// Case 7: Identify the ordinal number for 102
// When the number is 102,
// Then the function should return "102nd"

test("should return '102nd' for 102", () => {
expect(getOrdinalNumber(102)).toEqual("102nd");
});
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 scenario coverage. 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(102) ).toEqual("102nd");
});

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 the feedback I have grouped all the different teste-cases to categories.

some of the benefits of this approach are:

  • Scalability — We don't need to test every number, just representatives of each category.
  • Maintainability — It is easier to read and update tests when logic changes.
  • Comprehensive — It covers all the functional branches in the logic.
  • Avoids Redundancy — We won't waste time testing repetitive patterns unnecessarily.

Comment on lines 1 to 7
function repeat() {
return "hellohellohello";
if (arguments.length !== 2) {
throw new Error("Function requires exactly two arguments: str and count.");
}

const [str, count] = arguments;

Copy link
Contributor

Choose a reason for hiding this comment

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

Why not just declare the parameters as

function repeat(str, count) {
  ...

?

Copy link
Author

Choose a reason for hiding this comment

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

Yes we can declare the parameters in the function call and we will not need to declare const [str, count] = arguments;.

throw new Error("First argument must be a string.");
}

if (typeof count !== "number" || !Number.isInteger(count) || count < 0) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Similar to the case in get-ordinal-number.js,
can you think of a more concise way to express the condition of this 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.

There are two other ways that this condition can be expressed concisely.

concise (but potentially less readable):
if (!(Number.isInteger(count) && count >= 0))

and the other concise but more readable option:
if (!Number.isSafeInteger(count) || count < 0)

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

cjyuan commented Oct 8, 2025

In your PR description, the "Changelist" section is missing a header.

@AdnaanA AdnaanA added the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Oct 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.

Changes look good. I just have a few more suggestions.

Also, in the PR description, can you make the "Changelist" header to look like this?

Changelist


test("should return '4th' for 4", () => {
// category 4: all other numbers -> "th"
test("append 'th' to all other numbers", () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

When this test fails, the description "all other numbers" is not quite informative; one would need to read the other tests to figure out what numbers are considered as "other numbers".

Copy link
Author

Choose a reason for hiding this comment

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

fixed to more detailed description, "append 'th' to numbers ending in 0, 4–9, or 11–13"

Comment on lines +48 to +53
expect(getOrdinalNumber(12)).toEqual("12th");
expect(getOrdinalNumber(13)).toEqual("13th");
expect(getOrdinalNumber(14)).toEqual("14th");
expect(getOrdinalNumber(111)).toEqual("111th");
expect(getOrdinalNumber(112)).toEqual("112th");
expect(getOrdinalNumber(113)).toEqual("113th");
Copy link
Contributor

Choose a reason for hiding this comment

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

Why test the same numbers again in a separate test?

Copy link
Author

Choose a reason for hiding this comment

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

You are right all the test under category 5: special case for 11, 12, 13 -> "th" can be removed since they are tested in category 4: all other numbers -> "th"

@cjyuan cjyuan removed the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Oct 9, 2025
@AdnaanA AdnaanA added the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Oct 9, 2025
@cjyuan
Copy link
Contributor

cjyuan commented Oct 9, 2025

Changes to the code look good.

I wil mark this PR as complete first.

Can you also address this comment?
image

@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. Reviewed Volunteer to add when completing a review with trainee action still to take. labels Oct 9, 2025
@AdnaanA
Copy link
Author

AdnaanA commented Oct 9, 2025

Changes to the code look good.

I wil mark this PR as complete first.

Can you also address this comment? image

✔️ Done

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. 📅 Sprint 3 Assigned during Sprint 3 of this module
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants