Skip to content

Commit fdb7c91

Browse files
committed
Fix: resolve sprint-3 PR feedback (logic, tests, clarity)
1 parent d4e4a58 commit fdb7c91

File tree

3 files changed

+13
-40
lines changed

3 files changed

+13
-40
lines changed
Lines changed: 6 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,9 @@
1-
// implement a function countChar that counts the number of times a character occurs in a string
2-
const countChar = require("./count");
3-
// Given a string `str` and a single character `char` to search for,
4-
// When the countChar function is called with these inputs,
5-
// Then it should:
6-
7-
// Scenario: Multiple Occurrences
8-
// Given the input string `str`,
9-
// And a character `char` that occurs one or more times in `str` (e.g., 'a' in 'aaaaa'),
10-
// When the function is called with these inputs,
11-
// Then it should correctly count occurrences of `char`.
12-
13-
test("should count multiple occurrences of a character", () => {
14-
const str = "aaaaa";
15-
const char = "a";
16-
const count = countChar(str, char);
17-
expect(count).toEqual(5);
1+
test("should be case sensitive", () => {
2+
expect(countChar("Hello", "h")).toEqual(0);
3+
expect(countChar("Hello", "H")).toEqual(1);
184
});
195

20-
// Scenario: No Occurrences
21-
// Given the input string `str`,
22-
// And a character `char` that does not exist within `str`.
23-
// When the function is called with these inputs,
24-
// Then it should return 0, indicating that no occurrences of `char` were found.
25-
26-
test("should return 0 when the character does not exist in the string", () => {
27-
const str = "hello";
28-
const char = "z";
29-
const count = countChar(str, char);
30-
expect(count).toEqual(0);
6+
test("should work with non-alphabet characters", () => {
7+
expect(countChar("!!??!!", "!")).toEqual(4);
8+
expect(countChar("123123", "1")).toEqual(2);
319
});

Sprint-3/2-practice-tdd/get-ordinal-number.js

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,9 @@ function getOrdinalNumber(num) {
77
return num + "th";
88
}
99

10-
if (lastDigit === 1) {
11-
return num + "st";
12-
}
13-
14-
if (lastDigit === 2) {
15-
return num + "nd";
16-
}
17-
18-
if (lastDigit === 3) {
19-
return num + "rd";
20-
}
10+
if (lastDigit === 1) return num + "st";
11+
if (lastDigit === 2) return num + "nd";
12+
if (lastDigit === 3) return num + "rd";
2113

2214
return num + "th";
2315
}

Sprint-3/2-practice-tdd/get-ordinal-number.test.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,11 @@ test("should append 'th' for numbers ending with 11, 12, or 13", () => {
4646
});
4747

4848
// Case 5: All other numbers should end with "th"
49-
test("should append 'th' for all other numbers", () => {
49+
test("should append 'th' for numbers ending in 0, 4–9 (excluding 11, 12, 13)", () => {
50+
expect(getOrdinalNumber(0)).toEqual("0th");
5051
expect(getOrdinalNumber(4)).toEqual("4th");
52+
expect(getOrdinalNumber(5)).toEqual("5th");
53+
expect(getOrdinalNumber(9)).toEqual("9th");
5154
expect(getOrdinalNumber(10)).toEqual("10th");
5255
expect(getOrdinalNumber(100)).toEqual("100th");
5356
});

0 commit comments

Comments
 (0)