Skip to content

Conversation

@wankoak
Copy link

@wankoak wankoak commented Oct 24, 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

Added and pass tests for countChar, getOrdinalNumber, and repeat functions

Questions

No questions

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

Why not include a brief description of the changes made in this PR in the PR description?

typeof stringOfCharacters !== "string" ||
typeof findCharacter !== "string"
) {
return 0;
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 the caller distinguish the result of countChar(1234, 5) from the result of countChar("1234", "5")?

Comment on lines 3 to 5
if (typeof num !== "number" || isNaN(num)) {
return "";
}
Copy link
Contributor

Choose a reason for hiding this comment

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

3.1416 and Infinity could pass this test.

Comment on lines +17 to +21
// Case 2: Identify the ordinal number for 2
test("should return '2nd' for 2", () => {
expect(getOrdinalNumber(2)).toEqual("2nd");
});

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 +47 to +51
test("should return 'th' for numbers ending with 0, 4–9", () => {
expect(getOrdinalNumber(10)).toEqual("10th");
expect(getOrdinalNumber(14)).toEqual("14th");
expect(getOrdinalNumber(19)).toEqual("19th");
});
Copy link
Contributor

Choose a reason for hiding this comment

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

This test is good.

Comment on lines +33 to +37
test("should return '11th', '12th', '13th' for special cases", () => {
expect(getOrdinalNumber(11)).toEqual("11th");
expect(getOrdinalNumber(12)).toEqual("12th");
expect(getOrdinalNumber(13)).toEqual("13th");
});
Copy link
Contributor

Choose a reason for hiding this comment

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

When the person implementing the function see this test message, they may ask "what exactly are 'special 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 28, 2025
@github-actions
Copy link

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

1 similar comment
@github-actions
Copy link

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

@wankoak wankoak 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 29, 2025
@github-actions
Copy link

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

1 similar comment
@github-actions
Copy link

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

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.

  • Please update the PR description so that it can pass to automated check.

What does your "thumbs up" emoji mean? You reacted to my comment but did not make any change accordingly.
image

Comment on lines 2 to 9
// Ensure valid inputs
if (
typeof stringOfCharacters !== "string" ||
typeof findCharacter !== "string"
) {
return 0;
}

Copy link
Contributor

Choose a reason for hiding this comment

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

Why remove the check instead of strengthening it?

Comment on lines 11 to 17
let count = 0;
for (let char of stringOfCharacters) {
if (char === findCharacter) {
count++;
let total = 0;
for (let i=0; i < stringOfCharacters.length; i++){
if (findCharacter == stringOfCharacters[i]){
total++;
}
}

Copy link
Contributor

Choose a reason for hiding this comment

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

Why replace the for-of loop with a for loop? The former is more compact.

Comment on lines 2 to 6
// Ensure the input is a valid number
if (typeof num !== "number" || isNaN(num)) {
return "";
}

Copy link
Contributor

Choose a reason for hiding this comment

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

Why remove the check instead of strengthening it?

Copy link
Author

Choose a reason for hiding this comment

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

@cjyuan I was just trying to simplify the code

Comment on lines 7 to 6
const lastTwoDigits = num % 100;
const lastDigit = num % 10;

let result;

// Handle special cases: 11th, 12th, 13th
if (lastTwoDigits >= 11 && lastTwoDigits <= 13) {
return `${num}th`;
if (num % 100 == 11 || num % 100 == 12 || num % 100 == 13){
result = num.toString() + "th";
Copy link
Contributor

Choose a reason for hiding this comment

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

Why replace the previous approach

 const lastTwoDigits = num % 100;
  if (lastTwoDigits >= 11 && lastTwoDigits <= 13) {
    return `${num}th`;
    
    ...

with the current approach

let result;

  if (num % 100 == 11 || num % 100 == 12 || num % 100 == 13){
    result = num.toString() + "th";
    ...
  return result;

Copy link
Author

Choose a reason for hiding this comment

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

I was just trying to simplify the code

@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 29, 2025
@github-actions
Copy link

Your PR couldn't be matched to an assignment in this module.

Please check its title is in the correct format, and that you only have one PR per assignment.

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

@github-actions
Copy link

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

@wankoak
Copy link
Author

wankoak commented Oct 29, 2025

@cjyuan, just give me a few minutes. I'm in the market, I'll edit my code as soon as I get home.
The thumbs up means I understood what you said, and I will implement it.
And for the PR description it is very annoying how it keeps rejecting despite the fact that I removed the (Briefly explain your PR)
I'm trying @cjyuan just let me get home and fix the errors because I'm not with my laptop now

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

cjyuan commented Oct 30, 2025

The functions work.

Some of the code I commented remain unchanged, so I am not sure if you have addressed all my comments. Can you address all my previous comments?

@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 30, 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