Skip to content

Commit 34d7ce4

Browse files
committed
changed after feedback
1 parent 90db0f1 commit 34d7ce4

File tree

4 files changed

+86
-0
lines changed

4 files changed

+86
-0
lines changed

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
function getOrdinalNumber(num) {
2+
<<<<<<< Updated upstream
23
const lastdigit = num % 10;
34
if (lastdigit === 1) {
45
return `${num}st`;
@@ -13,6 +14,20 @@ function getOrdinalNumber(num) {
1314
} else {
1415
return `${num}th`;
1516
}
17+
=======
18+
const lastDigit = num % 10;
19+
const lastTwoDigits = num % 100;
20+
21+
if (lastTwoDigits >= 11 && lastTwoDigits <= 13) {
22+
return num + "th";
23+
}
24+
25+
if (lastDigit === 1) return num + "st";
26+
if (lastDigit === 2) return num + "nd";
27+
if (lastDigit === 3) return num + "rd";
28+
29+
return num + "th";
30+
>>>>>>> Stashed changes
1631
}
1732

1833
module.exports = getOrdinalNumber;

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

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,53 @@ test("should append 'st' for numbers ending with 1, except those ending with 11"
1919
expect(getOrdinalNumber(131)).toEqual("131st");
2020
});
2121

22+
<<<<<<< Updated upstream
2223
test("should append 'nd' for numbers ending with 2", () => {
24+
=======
25+
// Case 2: Numbers ending with 2 (but not 12)
26+
// When the number ends with 2, except those ending with 12,
27+
// Then the function should return a string by appending "nd" to the number
28+
test("Numbers ending with 2 (but not 12) should return 'nd'", () => {
29+
>>>>>>> Stashed changes
2330
expect(getOrdinalNumber(2)).toEqual("2nd");
2431
expect(getOrdinalNumber(22)).toEqual("22nd");
2532
expect(getOrdinalNumber(132)).toEqual("132nd");
2633
});
2734

35+
<<<<<<< Updated upstream
2836
test("should append 'rd' for numbers ending with 3, except those ending with 13", () => {
2937
expect(getOrdinalNumber(3)).toEqual("3rd");
3038
expect(getOrdinalNumber(33)).toEqual("33rd");
3139
expect(getOrdinalNumber(133)).toEqual("133rd");
3240
});
41+
=======
42+
// Case 3: Numbers ending with 3 (but not 13)
43+
// When the number ends with 3, except those ending with 13,
44+
// Then the function should return a string by appending "rd" to the number
45+
test("Numbers ending with 3 (but not 13) should return 'rd'", () => {
46+
expect(getOrdinalNumber(3)).toEqual("3rd");
47+
expect(getOrdinalNumber(23)).toEqual("23rd");
48+
expect(getOrdinalNumber(133)).toEqual("133rd");
49+
});
50+
51+
// Case 4: Numbers ending with 0,4-9
52+
// When the number ends with 0, 4, 5, 6, 7, 8, or 9,
53+
// Then the function should return a string by appending "th" to the number
54+
test("Numbers ending with 0,4-9 should return 'th'", () => {
55+
expect(getOrdinalNumber(4)).toEqual("4th");
56+
expect(getOrdinalNumber(10)).toEqual("10th");
57+
expect(getOrdinalNumber(25)).toEqual("25th");
58+
});
59+
60+
// Case 5: Numbers ending with 11, 12, or 13
61+
// When the number ends with 11, 12, or 13,
62+
// Then the function should return a string by appending "th" to the number
63+
test("Numbers ending with 11,12,13 should return 'th'", () => {
64+
expect(getOrdinalNumber(11)).toEqual("11th");
65+
expect(getOrdinalNumber(12)).toEqual("12th");
66+
expect(getOrdinalNumber(13)).toEqual("13th");
67+
expect(getOrdinalNumber(111)).toEqual("111th");
68+
expect(getOrdinalNumber(112)).toEqual("112th");
69+
expect(getOrdinalNumber(113)).toEqual("113th");
70+
});
71+
>>>>>>> Stashed changes
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,29 @@
11
function repeatStr(str, count) {
22
if (count < 0) {
3+
<<<<<<< Updated upstream
34
throw new Error("invalid count");
45
}
56
return str.repeat(count);
7+
=======
8+
throw new Error("Count cannot be negative");
9+
}
10+
11+
if (count === 0) {
12+
return "";
13+
}
14+
15+
if (count === 1) {
16+
return str;
17+
}
18+
19+
let result = "";
20+
21+
for (let i = 0; i < count; i++) {
22+
result += str;
23+
}
24+
25+
return result;
26+
>>>>>>> Stashed changes
627
}
728
// call the repeat function on the string and pass in count.
829
module.exports = repeatStr;

Sprint-3/2-practice-tdd/repeat-str.test.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ test("should repeat the string count times", () => {
2020
// Given a target string `str` and a `count` equal to 1,
2121
// When the repeatStr function is called with these inputs,
2222
// Then it should return the original `str` without repetition.
23+
test("given a string and count of 1, returns the original string", () => {
24+
expect(repeatStr("hello", 1)).toBe("hello");
25+
});
2326

2427
test("should repeat the string count times", () => {
2528
const str = "hello";
@@ -32,6 +35,9 @@ test("should repeat the string count times", () => {
3235
// Given a target string `str` and a `count` equal to 0,
3336
// When the repeatStr function is called with these inputs,
3437
// Then it should return an empty string.
38+
test("given a string and count of 0, returns an empty string", () => {
39+
expect(repeatStr("hello", 0)).toBe("");
40+
});
3541

3642
test("should repeat the string count times", () => {
3743
const str = "hello";
@@ -44,10 +50,15 @@ test("should repeat the string count times", () => {
4450
// Given a target string `str` and a negative integer `count`,
4551
// When the repeatStr function is called with these inputs,
4652
// Then it should throw an error, as negative counts are not valid.
53+
<<<<<<< Updated upstream
4754

4855
test("should repeat the string count times", () => {
4956
const str = "hello";
5057
const count = -2;
5158
// const repeatedStr = repeatStr(str, count);
5259
expect(() => repeatStr(str, count)).toThrow("invalid count");
60+
=======
61+
test("given a string and a negative count, throws an error", () => {
62+
expect(() => repeatStr("hello", -1)).toThrow();
63+
>>>>>>> Stashed changes
5364
});

0 commit comments

Comments
 (0)