Skip to content

Commit ac3f685

Browse files
committed
updated code based on reviewers feedback
1 parent 2da8e43 commit ac3f685

File tree

2 files changed

+29
-14
lines changed

2 files changed

+29
-14
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ function getOrdinalNumber(num) {
33
const lastDigit = num % 10;
44

55
if (lastTwoDigits >= 11 && lastTwoDigits <= 13) {
6-
return number + "th";
6+
return num + "th";
77
}
88

99
if (lastDigit === 1) {
Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,35 @@
11
const getOrdinalNumber = require("./get-ordinal-number");
2-
// In this week's prep, we started implementing getOrdinalNumber.
32

4-
// Continue testing and implementing getOrdinalNumber for additional cases.
5-
// Write your tests using Jest — remember to run your tests often for continual feedback.
6-
7-
// To ensure thorough testing, we need broad scenarios that cover all possible cases.
8-
// Listing individual values, however, can quickly lead to an unmanageable number of test cases.
9-
// Instead of writing tests for individual numbers, consider grouping all possible input values
10-
// into meaningful categories. Then, select representative samples from each category to test.
11-
// This approach improves coverage and makes our tests easier to maintain.
12-
13-
// Case 1: Numbers ending with 1 (but not 11)
14-
// When the number ends with 1, except those ending with 11,
15-
// Then the function should return a string by appending "st" to the number.
163
test("should append 'st' for numbers ending with 1, except those ending with 11", () => {
174
expect(getOrdinalNumber(1)).toEqual("1st");
185
expect(getOrdinalNumber(21)).toEqual("21st");
196
expect(getOrdinalNumber(131)).toEqual("131st");
207
});
8+
9+
test("should append 'nd' for numbers ending with 2, except those ending with 12", () => {
10+
expect(getOrdinalNumber(2)).toEqual("2nd");
11+
expect(getOrdinalNumber(22)).toEqual("22nd");
12+
expect(getOrdinalNumber(132)).toEqual("132nd");
13+
});
14+
15+
test("should append 'rd' for numbers ending with 3, except those ending with 13", () => {
16+
expect(getOrdinalNumber(3)).toEqual("3rd");
17+
expect(getOrdinalNumber(23)).toEqual("23rd");
18+
expect(getOrdinalNumber(133)).toEqual("133rd");
19+
});
20+
21+
test("should append 'th' for numbers ending with 11, 12, and 13", () => {
22+
expect(getOrdinalNumber(11)).toEqual("11th");
23+
expect(getOrdinalNumber(12)).toEqual("12th");
24+
expect(getOrdinalNumber(13)).toEqual("13th");
25+
expect(getOrdinalNumber(111)).toEqual("111th");
26+
expect(getOrdinalNumber(112)).toEqual("112th");
27+
expect(getOrdinalNumber(113)).toEqual("113th");
28+
});
29+
30+
test("should append 'th' for all other numbers", () => {
31+
expect(getOrdinalNumber(4)).toEqual("4th");
32+
expect(getOrdinalNumber(10)).toEqual("10th");
33+
expect(getOrdinalNumber(20)).toEqual("20th");
34+
expect(getOrdinalNumber(24)).toEqual("24th");
35+
});

0 commit comments

Comments
 (0)