Skip to content

Commit be4e103

Browse files
committed
Found solution for the 4th test in Sprint-3/2-practice-tdd/repeat.test.js
1 parent f322466 commit be4e103

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ function repeat(str, count) {
22
if (count === 0) {
33
return "";
44
}
5+
if (count < 0) {
6+
return "Error! Negative counts are not valid!";
7+
}
58

69
let repeatedStrCountTimes = "";
710

@@ -10,7 +13,7 @@ function repeat(str, count) {
1013
repeatedStrCountTimes += str;
1114
i++;
1215
}
13-
console.log(repeatedStrCountTimes);
16+
1417
return repeatedStrCountTimes;
1518
}
1619

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,9 @@ test("should return an empty string if count equal to 0", () => {
4242
// Given a target string str and a negative integer count,
4343
// When the repeat function is called with these inputs,
4444
// Then it should throw an error or return an appropriate error message, as negative counts are not valid.
45+
test("should return an appropriate error message if count equal to a negative integer", () => {
46+
const str = "negative";
47+
const count = -5;
48+
const repeatedStr = repeat(str, count);
49+
expect(repeatedStr).toEqual("Error! Negative counts are not valid!");
50+
});

0 commit comments

Comments
 (0)