File tree Expand file tree Collapse file tree 1 file changed +0
-37
lines changed
Expand file tree Collapse file tree 1 file changed +0
-37
lines changed Original file line number Diff line number Diff line change 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
192function repeatStr ( str , count ) {
203 if ( count < 0 ) {
@@ -23,24 +6,4 @@ function repeatStr(str, count) {
236 return str . repeat ( count ) ;
247}
258
26-
279module . 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- // });
You can’t perform that action at this time.
0 commit comments