Skip to content

Commit 6936466

Browse files
committed
worked on the feedback
1 parent d6a54b8 commit 6936466

File tree

6 files changed

+21
-37
lines changed

6 files changed

+21
-37
lines changed

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

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
function countChar(stringOfCharacters, findCharacter) {
2-
if (findCharacter === "")
3-
return 0;
4-
else
5-
return stringOfCharacters.split(findCharacter).length -1;
2+
if (findCharacter.length === 0) return 0;
3+
else return stringOfCharacters.split(findCharacter).length - 1;
64
}
75

8-
module.exports = countChar;
6+
module.exports = countChar;

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ test("should return 0 if there are no occurrences of a character", () => {
3030
expect(count).toEqual(0);
3131
});
3232

33-
3433
// Scenario 3: Single Occurrence
3534
// Given the input string `str`,
3635
// And a character `char` that exists only once within `str`.
@@ -70,15 +69,15 @@ test("should return multiple occurrences of empty spaces in the string", () => {
7069
expect(count).toEqual(10);
7170
});
7271

73-
7472
// Scenario 6: No occurrences if the char is just an empty char
7573
// Given the input string `str` that contains any number of characters or no characters at all,
7674
// And a character `char` which is empty ''.
7775
// When the function is called with these inputs,
7876
// Then it should return 0 as there is nothing to count as the char is just empty.
7977

8078
test("should return 0 as the char is just empty", () => {
81-
const str = "Hi I am a string that can be empty or not empty but I can't count empty characters.";
79+
const str =
80+
"Hi I am a string that can be empty or not empty but I can't count empty characters.";
8281
const char = "";
8382
const count = countChar(str, char);
8483
expect(count).toEqual(0);
@@ -95,4 +94,4 @@ test("should count multiple occurrences of a character", () => {
9594
const char = "a";
9695
const count = countChar(str, char);
9796
expect(count).toEqual(4);
98-
});
97+
});

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

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,11 @@ function getOrdinalNumber(num) {
22
let numberString = String(num);
33
lastTwoCharactersNumberString = numberString.slice(-2);
44
lastCharacterNumberString = numberString.slice(-1);
5-
if(lastTwoCharactersNumberString === "11")
6-
return num+ "th";
7-
else if(lastCharacterNumberString === "1")
8-
return num+ "st";
9-
else if(lastCharacterNumberString === "2")
10-
return num+"nd";
11-
else if(lastCharacterNumberString === "3")
12-
return num + "rd";
13-
else
14-
return num + "th";
5+
if (lastTwoCharactersNumberString === "11") return num + "th";
6+
else if (lastCharacterNumberString === "1") return num + "st";
7+
else if (lastCharacterNumberString === "2") return num + "nd";
8+
else if (lastCharacterNumberString === "3") return num + "rd";
9+
else return num + "th";
1510
}
1611

17-
module.exports = getOrdinalNumber;
12+
module.exports = getOrdinalNumber;

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,14 @@ test("should append 'st' for numbers ending with 2", () => {
4141
expect(getOrdinalNumber(-82)).toEqual("-82nd");
4242
});
4343

44-
4544
// Case 4: Numbers ending with 3
4645
// When the number is ending with 3,
4746
// Then the function should return a string by appending "rd" to the number.
4847
test("should append 'st' for numbers ending with 3", () => {
4948
expect(getOrdinalNumber(3)).toEqual("3rd");
5049
expect(getOrdinalNumber(33)).toEqual("33rd");
5150
expect(getOrdinalNumber(183)).toEqual("183rd");
52-
expect(getOrdinalNumber(-903)).toEqual("-903rd");
51+
expect(getOrdinalNumber(-903)).toEqual("-903rd");
5352
});
5453

5554
// Case 5: Numbers not ending 1, 2 and 3 except 11
@@ -63,6 +62,4 @@ test("should append 'th' for numbers not ending with 1, 2 and 3 except those end
6362
expect(getOrdinalNumber(1000)).toEqual("1000th");
6463
expect(getOrdinalNumber(87939)).toEqual("87939th");
6564
expect(getOrdinalNumber(-780987)).toEqual("-780987th");
66-
6765
});
68-
Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,12 @@
11
function repeatStr(str, count) {
2-
try{
3-
if(count === 0)
4-
return "";
5-
else if(count === 1)
6-
return str;
7-
else if(count < 0)
8-
throw new Error("an error is thrown");
9-
else
10-
return str.repeat(count);
11-
}
12-
catch(e){
2+
try {
3+
if (count === 0) return "";
4+
else if (count === 1) return str;
5+
else if (count < 0) throw new Error("an error is thrown");
6+
else return str.repeat(count);
7+
} catch (e) {
138
return e.message;
149
}
1510
}
1611

17-
module.exports = repeatStr;
12+
module.exports = repeatStr;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,4 @@ test("should repeat the string count times", () => {
4747
const count = -2;
4848
const repeatedStr = repeatStr(str, count);
4949
expect(repeatedStr).toEqual("an error is thrown");
50-
});
50+
});

0 commit comments

Comments
 (0)