Skip to content

Commit f322466

Browse files
committed
Found solution for the 2 and 3 test in Sprint-3/2-practice-tdd/repeat.test.js
1 parent 87433e4 commit f322466

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
11
function repeat(str, count) {
2+
if (count === 0) {
3+
return "";
4+
}
5+
26
let repeatedStrCountTimes = "";
37

48
let i = 0;
59
while (i < count) {
610
repeatedStrCountTimes += str;
711
i++;
812
}
13+
console.log(repeatedStrCountTimes);
914
return repeatedStrCountTimes;
1015
}
1116

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,23 @@ test("should repeat the string count times", () => {
2020
// Given a target string str and a count equal to 1,
2121
// When the repeat function is called with these inputs,
2222
// Then it should return the original str without repetition, ensuring that a count of 1 results in no repetition.
23+
test("should return the original string without repetition if count equal to 1", () => {
24+
const str = "Alone";
25+
const count = 1;
26+
const repeatedStr = repeat(str, count);
27+
expect(repeatedStr).toEqual("Alone");
28+
});
2329

2430
// case: Handle Count of 0:
2531
// Given a target string str and a count equal to 0,
2632
// When the repeat function is called with these inputs,
2733
// Then it should return an empty string, ensuring that a count of 0 results in an empty output.
34+
test("should return an empty string if count equal to 0", () => {
35+
const str = "nonsense";
36+
const count = 0;
37+
const repeatedStr = repeat(str, count);
38+
expect(repeatedStr).toEqual("");
39+
});
2840

2941
// case: Negative Count:
3042
// Given a target string str and a negative integer count,

0 commit comments

Comments
 (0)