Skip to content

Commit 5ef5dac

Browse files
committed
fixing codes based on mentor feedback
1 parent 6e54c76 commit 5ef5dac

3 files changed

Lines changed: 27 additions & 13 deletions

File tree

Sprint-3/2-practice-tdd/count.test.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,19 @@ const countChar = require("./count");
1010
// When the function is called with these inputs,
1111
// Then it should correctly count occurrences of `char`.
1212

13-
test("should count multiple occurrences of a character", () => {
13+
test("The function should return the number of times a character appears ", () => {
1414
const str = "aaaaa";
1515
const char = "a";
1616
const count = countChar(str, char);
1717
expect(count).toEqual(5);
1818
});
19-
test("should count multiple occurrences of a character", () => {
19+
test("The function should return the number of times a character appears", () => {
2020
const str = "hello";
2121
const char = "l";
2222
const count = countChar(str, char);
2323
expect(count).toEqual(2);
2424
});
25-
test("should count multiple occurrences of a character", () => {
25+
test("The function should return the number of times a character appears", () => {
2626
const str = "speed";
2727
const char = "e";
2828
const count = countChar(str, char);
@@ -34,19 +34,19 @@ test("should count multiple occurrences of a character", () => {
3434
// And a character `char` that does not exist within `str`.
3535
// When the function is called with these inputs,
3636
// Then it should return 0, indicating that no occurrences of `char` were found.
37-
test("should count multiple occurrences of a character", () => {
37+
test("the function should return 0 when there are no appears of the character", () => {
3838
const str = "kkkk";
3939
const char = "l";
4040
const count = countChar(str, char);
4141
expect(count).toEqual(0);
4242
});
43-
test("should count multiple occurrences of a character", () => {
43+
test("the function should return 0 when there are no appears of the character", () => {
4444
const str = "bbbb";
4545
const char = "c";
4646
const count = countChar(str, char);
4747
expect(count).toEqual(0);
4848
});
49-
test("should count multiple occurrences of a character", () => {
49+
test("the function should return 0 when there are no appears of the character", () => {
5050
const str = "mmmmmzmze";
5151
const char = "d";
5252
const count = countChar(str, char);

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,19 @@ test("should append 'rd' for numbers ending with 3, except those ending with 13"
3434
expect(getOrdinalNumber(33)).toEqual("33rd");
3535
expect(getOrdinalNumber(133)).toEqual("133rd");
3636
});
37+
//Case 4: Numbers ending with 11,12 and 13
38+
// When the number ends with 11,12 and 13,
39+
// Then the function should return a string by appending "th" to the number.
40+
test("should append 'th' for numbers ending with 11,12 and 13", () => {
41+
expect(getOrdinalNumber(1011)).toEqual("1011th");
42+
expect(getOrdinalNumber(312)).toEqual("312th");
43+
expect(getOrdinalNumber(113)).toEqual("113th");
44+
});
45+
//Case 5: Numbers 11,12 and 13
46+
// When the number is 11,12 and 13,
47+
// Then the function should return a string by appending "th" to the number.
48+
test("should append 'th' for numbers ending with 11,12 and 13", () => {
49+
expect(getOrdinalNumber(11)).toEqual("11th");
50+
expect(getOrdinalNumber(12)).toEqual("12th");
51+
expect(getOrdinalNumber(13)).toEqual("13th");
52+
});

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

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,12 @@ function repeatStr(str, num) {
22
let result = "";
33
// Your implementation of this function must *not* call String.prototype.repeat (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/repeat).
44
// The goal is to re-implement that function, not to use it.
5-
for (let i = 0; i < num; i++) {
6-
result += str;
5+
6+
if (num < 0) {
7+
throw new Error();
78
}
8-
if (num > 0) {
9-
return result;
10-
} else if (num === 0) {
11-
return "";
12-
} else throw new error();
9+
10+
return str.repeat(num);
1311
}
1412

1513
module.exports = repeatStr;

0 commit comments

Comments
 (0)