Skip to content

Commit 0af1ee0

Browse files
committed
refactor: streamline repeatStr function by removing commented code and utilizing built-in method
1 parent 49a3b76 commit 0af1ee0

File tree

1 file changed

+0
-37
lines changed

1 file changed

+0
-37
lines changed
Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,3 @@
1-
// function repeatStr(str, count) {
2-
// if (count < 0) {
3-
// throw new Error("count cannot be negative");
4-
// }
5-
6-
// let result = "";
7-
// for (let i = 0; i < count; i++) {
8-
// result = result + str;
9-
// }
10-
// return result;
11-
// }
12-
13-
// The repeat() method of String values constructs and returns
14-
// a new string which contains the specified number of copies
15-
// of this string, concatenated together.
16-
//repeatStr("abc", 3); // "abcabcabc"
17-
181
//refactored function using built-in method
192
function repeatStr(str, count) {
203
if (count < 0) {
@@ -23,24 +6,4 @@ function repeatStr(str, count) {
236
return str.repeat(count);
247
}
258

26-
279
module.exports = repeatStr;
28-
29-
30-
31-
32-
33-
// // Case: Manual inspection of the Error object
34-
// // We use try/catch to log the error message to the console
35-
// // to verify it's working as expected without breaking the test suite.
36-
// test("Should log the specific error message to the console", () => {
37-
// try {
38-
// repeatStr("hi", -3);
39-
// } catch (error) {
40-
// console.log("Verified Error Message ->", error.message);
41-
42-
// // Check if the message is exactly what we defined
43-
// expect(error.message).toBe("count cannot be negative");
44-
// }
45-
46-
// });

0 commit comments

Comments
 (0)