Skip to content

Commit f980882

Browse files
author
Pretty Taruvinga
committed
fixed the function
1 parent ab1f15e commit f980882

File tree

1 file changed

+3
-29
lines changed

1 file changed

+3
-29
lines changed
Lines changed: 3 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
function repeatStr(n, str) {
2+
if (!Number.isInteger(n) || n < 0) {
3+
throw new Error("Count must be a non-negative integer");
4+
}
25
let result = "";
36
for (let i = 0; i < n; i++) {
47
result += str;
@@ -7,32 +10,3 @@ function repeatStr(n, str) {
710
}
811

912
module.exports = repeatStr;
10-
// const repeatStr = require("./repeat-str");
11-
// Given a target string `str` and a positive integer `count`,
12-
// When the repeatStr function is called with these inputs,
13-
// Then it should:
14-
// test("repeats a string n times", () => {
15-
// expect(repeatStr(3, "hello")).toBe("hellohellohello");
16-
// });
17-
const repeatStr = require("./repeat-str");
18-
test("repeats a string n times", () => {
19-
expect(repeatStr(3, "hello")).toBe("hellohellohello");
20-
});
21-
// test("repeats a different string", () => {
22-
// expect(repeatStr(2, "abc")).toBe("abcabc");
23-
// });
24-
test("repeats a different string", () => {
25-
expect(repeatStr(2, "abc")).toBe("abcabc");
26-
});
27-
// test("returns empty string when n is 0", () => {
28-
// expect(repeatStr(0, "hi")).toBe("");
29-
// });
30-
test("returns empty string when n is 0", () => {
31-
expect(repeatStr(0, "hi")).toBe("");
32-
});
33-
// test("returns empty string when n is 0", () => {
34-
// expect(repeatStr(0, "hi")).toBe("");
35-
// });
36-
test("returns empty string when n is 0", () => {
37-
expect(repeatStr(0, "hi")).toBe("");
38-
});

0 commit comments

Comments
 (0)