Skip to content

Commit 0cd7886

Browse files
review comments implemented
1 parent 21c6130 commit 0cd7886

6 files changed

Lines changed: 35 additions & 35 deletions

File tree

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
function countChar(stringOfCharacters, findCharacter) {
2-
return stringOfCharacters.split(findCharacter).length-1
2+
return stringOfCharacters.split(findCharacter).length - 1;
33
}
44

55
module.exports = countChar;

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

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,33 +17,32 @@ test("should count multiple occurrences of a character", () => {
1717
expect(count).toEqual(5);
1818
});
1919
test("should count multiple occurrences of a character", () => {
20-
const str = "pneumonoultramicroscopicsilicovolcanoconoisis";
21-
const char = "o";
20+
const str = "international";
21+
const char = "n";
2222
const count = countChar(str, char);
23-
expect(count).toEqual(9);
23+
expect(count).toEqual(3);
2424
});
2525
test("should count multiple occurrences of a character", () => {
26-
const str = "pneumonoultramicroscopicsilicovolcanoconoisis";
27-
const char = "i";
26+
const str = "crisis";
27+
const char = "s";
2828
const count = countChar(str, char);
29-
expect(count).toEqual(6);
29+
expect(count).toEqual(2);
3030
});
3131

32-
3332
// Scenario: No Occurrences
3433
// Given the input string `str`,
3534
// And a character `char` that does not exist within `str`.
3635
// When the function is called with these inputs,
3736
// Then it should return 0, indicating that no occurrences of `char` were found.
38-
test("should count multiple occurrences of a character", () => {
37+
test("should return 0, indicating that no occurrences of `char` were found", () => {
3938
const str = "interesting";
4039
const char = "b";
4140
const count = countChar(str, char);
4241
expect(count).toEqual(0);
4342
});
44-
test("should count multiple occurrences of a character", () => {
43+
test("should return 0, indicating that no occurrences of `char` were found", () => {
4544
const str = "future";
4645
const char = "m";
4746
const count = countChar(str, char);
4847
expect(count).toEqual(0);
49-
});
48+
});

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

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
11
function getOrdinalNumber(num) {
2-
if ([11, 12, 13].includes(num % 100)){
3-
return num + "th"
2+
if ([11, 12, 13].includes(num % 100)) {
3+
return num + "th";
44
}
5-
if (String(num).at(-1)=== "1"){
6-
return num + "st"
5+
if (String(num).at(-1) === "1") {
6+
return num + "st";
77
}
8-
if (String(num).at(-1) === "2"){
9-
return num + "nd"
8+
if (String(num).at(-1) === "2") {
9+
return num + "nd";
1010
}
11-
if (String(num).at(-1) === "3"){
12-
return num + "rd"
13-
}
14-
else{
15-
return num + "th"
11+
if (String(num).at(-1) === "3") {
12+
return num + "rd";
13+
} else {
14+
return num + "th";
1615
}
1716
}
1817

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,4 @@ test("should append 'nd' for numbers ending with 3", () => {
4343
expect(getOrdinalNumber(3)).toEqual("3rd");
4444
expect(getOrdinalNumber(2023)).toEqual("2023rd");
4545
expect(getOrdinalNumber(16733)).toEqual("16733rd");
46-
});
46+
});
Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
function repeatStr(str, count) {
22
// 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).
33
// The goal is to re-implement that function, not to use it.
4-
if(count >= 0){
5-
return str.repeat(count);
6-
}
7-
else{
4+
let result = "";
5+
if (count < 0) {
86
throw new Error("Invalid count");
7+
} else {
8+
for (let i = 0; i < count; i++) {
9+
result += str;
10+
}
11+
return result;
912
}
1013
}
11-
1214
module.exports = repeatStr;

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,13 @@ test("should repeat the string count times", () => {
2626
// Given a target string `str` and a `count` equal to 1,
2727
// When the repeatStr function is called with these inputs,
2828
// Then it should return the original `str` without repetition.
29-
test("should repeat the string count times", () => {
29+
test("should repeat the string once", () => {
3030
const str = "hello";
3131
const count = 1;
3232
const repeatedStr = repeatStr(str, count);
3333
expect(repeatedStr).toEqual("hello");
3434
});
35-
test("should repeat the string count times", () => {
35+
test("should repeat the string once", () => {
3636
const str = "codeyourfuture";
3737
const count = 1;
3838
const repeatedStr = repeatStr(str, count);
@@ -42,13 +42,13 @@ test("should repeat the string count times", () => {
4242
// Given a target string `str` and a `count` equal to 0,
4343
// When the repeatStr function is called with these inputs,
4444
// Then it should return an empty string.
45-
test("should repeat the string count times", () => {
45+
test("should return an empty string", () => {
4646
const str = "hello";
4747
const count = 0;
4848
const repeatedStr = repeatStr(str, count);
4949
expect(repeatedStr).toEqual("");
5050
});
51-
test("should repeat the string count times", () => {
51+
test("should return an empty string", () => {
5252
const str = "codeyourfuture";
5353
const count = 0;
5454
const repeatedStr = repeatStr(str, count);
@@ -58,13 +58,13 @@ test("should repeat the string count times", () => {
5858
// Given a target string `str` and a negative integer `count`,
5959
// When the repeatStr function is called with these inputs,
6060
// Then it should throw an error, as negative counts are not valid.
61-
test("should repeat the string count times", () => {
61+
test("should throw an error for negative integer", () => {
6262
const str = "hello";
6363
const count = -4;
6464
expect(() => repeatStr(str, count)).toThrow("Invalid count");
6565
});
66-
test("should repeat the string count times", () => {
66+
test("should throw an error for negative integer", () => {
6767
const str = "codeyourfuture";
6868
const count = -1;
6969
expect(() => repeatStr(str, count)).toThrow("Invalid count");
70-
});
70+
});

0 commit comments

Comments
 (0)