Skip to content

Commit d09a54e

Browse files
committed
write function repeat-str()
1 parent 5282cbf commit d09a54e

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
function repeatStr() {
2-
return "hellohellohello";
1+
function repeatStr(str, count) {
2+
if (count >= 0) return str.repeat(count);
3+
else throw new Error("Invalid format: count cannot be");
34
}
45

56
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
@@ -49,5 +49,5 @@ test("should throw an error when count is negative", () => {
4949
const str = "hello";
5050
const count = -6;
5151
const repeatedStr = () => repeatStr(str, count);
52-
expect(repeatedStr).toThrow(/negative/);
52+
expect(repeatedStr).toThrow(/Invalid format/);
5353
});

0 commit comments

Comments
 (0)