Skip to content

Commit 77bc6be

Browse files
author
Pretty Taruvinga
committed
refactor: simplify repeatStr using String.prototype.repeat
1 parent 4098eb1 commit 77bc6be

File tree

2 files changed

+23
-4
lines changed

2 files changed

+23
-4
lines changed

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

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,31 @@ function repeatStr(n, str) {
88

99
module.exports = repeatStr;
1010
// const repeatStr = require("./repeat-str");
11-
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:
1214
// test("repeats a string n times", () => {
1315
// expect(repeatStr(3, "hello")).toBe("hellohellohello");
1416
// });
15-
17+
const repeatStr = require("./repeat-str");
18+
test("repeats a string n times", () => {
19+
expect(repeatStr(3, "hello")).toBe("hellohellohello");
20+
});
1621
// test("repeats a different string", () => {
1722
// expect(repeatStr(2, "abc")).toBe("abcabc");
1823
// });
19-
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+
});
2033
// test("returns empty string when n is 0", () => {
2134
// expect(repeatStr(0, "hi")).toBe("");
2235
// });
36+
test("returns empty string when n is 0", () => {
37+
expect(repeatStr(0, "hi")).toBe("");
38+
});

package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,8 @@
1111
"license": "ISC",
1212
"dependencies": {
1313
"jest": "^29.7.0"
14+
},
15+
"devDependencies": {
16+
"jest-environment-jsdom": "^30.2.0"
1417
}
15-
}
18+
}

0 commit comments

Comments
 (0)