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