--- id: afcc8d540bea9ea2669306b6 title: Repeat a String Repeat a String challengeType: 5 videoUrl: '' localeTitle: 重复一个字符串重复字符串 --- ## Description
num times(第二个参数)重复给定的字符串str (第一个参数)。如果num不是正数,则返回空字符串。如果卡住,请记得使用Read-Search-Ask 。编写自己的代码。
## Instructions
## Tests
```yml tests: - text: 'repeatStringNumTimes("*", 3)应该返回"***" 。' testString: assert(repeatStringNumTimes("*", 3) === "***"); - text: 'repeatStringNumTimes("abc", 3)应该返回"abcabcabc" 。' testString: assert(repeatStringNumTimes("abc", 3) === "abcabcabc"); - text: 'repeatStringNumTimes("abc", 4)应返回"abcabcabcabc" 。' testString: assert(repeatStringNumTimes("abc", 4) === "abcabcabcabc"); - text: 'repeatStringNumTimes("abc", 1)应该返回"abc" 。' testString: assert(repeatStringNumTimes("abc", 1) === "abc"); - text: 'repeatStringNumTimes("*", 8)应该返回"********" 。' testString: assert(repeatStringNumTimes("*", 8) === "********"); - text: 'repeatStringNumTimes("abc", -2)应返回"" 。' testString: assert(repeatStringNumTimes("abc", -2) === ""); - text: 不应使用内置的repeat()方法 testString: assert(!/\.repeat/g.test(code)); ```
## Challenge Seed
```js function repeatStringNumTimes(str, num) { // repeat after me return str; } repeatStringNumTimes("abc", 3); ```
## Solution
```js // solution required ``` /section>