File tree Expand file tree Collapse file tree 1 file changed +34
-11
lines changed
Expand file tree Collapse file tree 1 file changed +34
-11
lines changed Original file line number Diff line number Diff line change 1- function repeat ( str , count ) {
2- if ( count < 0 ) {
3- throw new Error ( "Count must be non-negative" ) ;
4- }
5-
6- let result = "" ;
7- for ( let i = 0 ; i < count ; i ++ ) {
8- result += str ;
9- }
10- return result ;
1+ function repeat ( ) {
2+ if ( arguments [ 1 ] < 0 ) throw new Error ( "Count must be non-negative" ) ;
3+ return arguments [ 0 ] . repeat ( arguments [ 1 ] ) ;
114}
5+ //other implementation
6+ // function repeat(str, count) {
7+ // if (count < 0) {
8+ // throw new Error("Count must be non-negative");
9+ // }
1210
13- module . exports = repeat ;
11+ // let result = "";
12+ // for (let i = 0; i < count; i++) {
13+ // result += str;
14+ // }
15+ // return result;
16+ // }
17+
18+ // module.exports = repeat;
19+
20+ // function repeat() {
21+ // const str = arguments[0];
22+ // const count = arguments[1];
23+
24+ // if (count < 0) {
25+ // throw new Error("Count must be non-negative");
26+ // }
27+
28+ // let output = "";
29+ // for (let i = 0; i < count; i++) {
30+ // output += str;
31+ // }
32+
33+ // return output;
34+ // }
35+
36+ // module.exports = repeat;
You can’t perform that action at this time.
0 commit comments