Skip to content

Brussels | ITP-2026-1 | Meysam Razagh | Sprint-3 | Practice TDD#79

Open
Epunch wants to merge 4 commits intoHackYourFutureBelgium:mainfrom
Epunch:coursework/sprint-3-practice-tdd
Open

Brussels | ITP-2026-1 | Meysam Razagh | Sprint-3 | Practice TDD#79
Epunch wants to merge 4 commits intoHackYourFutureBelgium:mainfrom
Epunch:coursework/sprint-3-practice-tdd

Conversation

@Epunch
Copy link
Copy Markdown

@Epunch Epunch commented Apr 23, 2026

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

In this PR, I practiced Test-Driven Development (TDD) by implementing three functions with their corresponding Jest tests:

  • countChar: A function that counts occurrences of a character in a string.
  • repeat: A function that repeats a string a specified number of times, including handling edge cases like 0 and negative counts.
  • getOrdinalNumber: A function that converts numbers to their ordinal format (1st, 2nd, 3rd, etc.).
  • All logic was developed following the Red-Green-Refactor cycle, ensuring 100% test coverage for the required scenarios.

Questions

No questions, everything went smoothly!

}

return num + "th";
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This works for all numbers up to 20. Even better would be if you can make it work for all numbers. Right now 21 would output 21th instead of 21st and so on

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

@noahg9 I've refactored the function using the modulo operator to ensure it's scalable for all numbers. It now passes the new test cases. Thanks for the feedback!

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Perfect!

test("should return 'th' for numbers other than 1, 2, or 3", () => {
expect(getOrdinalNumber(4)).toEqual("4th");
expect(getOrdinalNumber(10)).toEqual("10th");
});
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Add tests for numbers ending in 1, 2 or 3 after 20. They will fail with your current implementation

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

@noahg9 I've added the test cases for numbers ending in 1, 2, and 3 after 20 as requested. They are now passing with the updated logic in the main file.

@Epunch Epunch changed the title Brussels | ITP-2026-1 | Meysam Razagh | Sprint-3 Practice TDD Brussels | ITP-2026-1 | Meysam Razagh | Sprint-3 | Practice TDD May 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants