-
Notifications
You must be signed in to change notification settings - Fork 20
Brussels | ITP-2026-1 | Meysam Razagh | Sprint-3 | Practice TDD #79
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
48e0a48
18b1eac
3c75653
ad2c88e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,13 @@ | ||
| function countChar(stringOfCharacters, findCharacter) { | ||
| return 5 | ||
| let variable = 0; // moteghayer baraye shomaresh | ||
|
|
||
| for (let i = 0; i < stringOfCharacters.length; i++) { | ||
| if (stringOfCharacters[i] === findCharacter) { | ||
| variable++; | ||
| } | ||
| } | ||
|
|
||
| return variable; | ||
| } | ||
|
|
||
| module.exports = countChar; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,17 @@ | ||
| function getOrdinalNumber(num) { | ||
| return "1st"; | ||
| // Handle the 'teen' exceptions (11, 12, 13) that always end in 'th' | ||
| if (num % 100 >= 11 && num % 100 <= 13) { | ||
| return num + "th"; | ||
| } | ||
|
|
||
| // Identify the last digit to determine the correct suffix for all other numbers | ||
| const lastDigit = num % 10; | ||
|
|
||
| if (lastDigit === 1) return num + "st"; | ||
| if (lastDigit === 2) return num + "nd"; | ||
| if (lastDigit === 3) return num + "rd"; | ||
|
|
||
| return num + "th"; | ||
| } | ||
|
|
||
| module.exports = getOrdinalNumber; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,13 +1,38 @@ | ||
| const getOrdinalNumber = require("./get-ordinal-number"); | ||
| // In this week's prep, we started implementing getOrdinalNumber | ||
|
|
||
| // continue testing and implementing getOrdinalNumber for additional cases | ||
| // Write your tests using Jest - remember to run your tests often for continual feedback | ||
| // Given a number, | ||
| // When the getOrdinalNumber function is called with this input, | ||
| // Then it should return the correct ordinal string. | ||
|
|
||
| // Case 1: Identify the ordinal number for 1 | ||
| // When the number is 1, | ||
| // Then the function should return "1st" | ||
|
|
||
| test("should return '1st' for 1", () => { | ||
| expect(getOrdinalNumber(1)).toEqual("1st"); | ||
| }); | ||
|
|
||
| // Case 2: Identify the ordinal number for 2 | ||
| test("should return '2nd' for 2", () => { | ||
| expect(getOrdinalNumber(2)).toEqual("2nd"); | ||
| }); | ||
|
|
||
| // Case 3: Identify the ordinal number for 3 | ||
| test("should return '3rd' for 3", () => { | ||
| expect(getOrdinalNumber(3)).toEqual("3rd"); | ||
| }); | ||
|
|
||
| // Case 4: Handle other numbers | ||
| test("should return 'th' for numbers other than 1, 2, or 3", () => { | ||
| expect(getOrdinalNumber(4)).toEqual("4th"); | ||
| expect(getOrdinalNumber(10)).toEqual("10th"); | ||
| }); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
| // Case 5: Handle numbers ending in 1, 2, or 3 after 20 | ||
| test("should return '21st' for 21", () => { | ||
| expect(getOrdinalNumber(21)).toEqual("21st"); | ||
| }); | ||
|
|
||
| test("should return '22nd' for 22", () => { | ||
| expect(getOrdinalNumber(22)).toEqual("22nd"); | ||
| }); | ||
|
|
||
| test("should return '23rd' for 23", () => { | ||
| expect(getOrdinalNumber(23)).toEqual("23rd"); | ||
| }); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,15 @@ | ||
| function repeat() { | ||
| return "hellohellohello"; | ||
| function repeat(str, count) { | ||
| if (count < 0) { | ||
| throw new Error("Count must be a non-negative integer"); | ||
| } | ||
|
|
||
| let variable = ""; // inja natije ro jam mikonim | ||
|
|
||
| for (let i = 0; i < count; i++) { | ||
| variable += str; | ||
| } | ||
|
|
||
| return variable; | ||
| } | ||
|
|
||
| module.exports = repeat; |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perfect!