Skip to content

Commit 019749e

Browse files
committed
Address PR review: clearer count tests, empty string case, simplify ordinal logic
1 parent 1e25c6e commit 019749e

3 files changed

Lines changed: 28 additions & 11 deletions

File tree

‎practice-tdd/count.test.js‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ test("should count multiple occurrences of a character", () => {
2323
// When the function is called with these inputs,
2424
// Then it should return 0, indicating that no occurrences of `char` were found.
2525

26-
test("should count multiple occurrences of a character including upper cases", () => {
26+
test("should count character occurrences case-insensitively", () => {
2727
const str = "BanaNa";
2828
const char = "n";
2929
const count = countChar(str, char);
@@ -36,3 +36,7 @@ test("should count 0 occurrences of a character", () => {
3636
const count = countChar(str, char);
3737
expect(count).toEqual(0);
3838
});
39+
40+
test("should return 0 when the string is empty", () => {
41+
expect(countChar("", "a")).toEqual(0);
42+
});

‎practice-tdd/get-ordinal-number.js‎

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,24 @@
11
export function getOrdinalNumber(num) {
2-
return num % 100 === 11 || num % 100 === 12 || num % 100 === 13
3-
? `${num}th`
4-
: num % 10 === 1
5-
? `${num}st`
6-
: num % 10 === 2
7-
? `${num}nd`
8-
: num % 10 === 3
9-
? `${num}rd`
10-
: `${num}th`;
2+
const lastTwoDigits = num % 100;
3+
const lastDigit = num % 10;
4+
5+
if (lastTwoDigits === 11 || lastTwoDigits === 12 || lastTwoDigits === 13) {
6+
return `${num}th`;
7+
}
8+
9+
if (lastDigit === 1) {
10+
return `${num}st`;
11+
}
12+
13+
if (lastDigit === 2) {
14+
return `${num}nd`;
15+
}
16+
17+
if (lastDigit === 3) {
18+
return `${num}rd`;
19+
}
20+
21+
return `${num}th`;
1122
}
23+
24+

‎practice-tdd/get-ordinal-number.test.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ test("should append 'th' for numbers ending with 11, 12, or 13.", () => {
3737
expect(getOrdinalNumber(13)).toEqual("13th");
3838
});
3939

40-
test("should append 'th' for numbers ending with 0, 4, or big numbers.", () => {
40+
test("should append 'th' for numbers ending in 0 or 4–9", () => {
4141
expect(getOrdinalNumber(10)).toEqual("10th");
4242
expect(getOrdinalNumber(30)).toEqual("30th");
4343
expect(getOrdinalNumber(500)).toEqual("500th");

0 commit comments

Comments
 (0)