2018-10-10 18:03:03 -04:00
|
|
|
|
---
|
|
|
|
|
id: afcc8d540bea9ea2669306b6
|
|
|
|
|
title: Repeat a String Repeat a String
|
|
|
|
|
isRequired: true
|
|
|
|
|
challengeType: 5
|
|
|
|
|
videoUrl: ''
|
|
|
|
|
localeTitle: 重复一个字符串重复字符串
|
|
|
|
|
---
|
|
|
|
|
|
|
|
|
|
## Description
|
2019-11-19 19:54:48 -05:00
|
|
|
|
<section id="description">为<code>num</code> times(第二个参数)重复给定的字符串<code>str</code> (第一个参数)。如果<code>num</code>不是正数,则返回空字符串。如果卡住,请记得使用<a href="https://www.freecodecamp.org/forum/t/how-to-get-help-when-you-are-stuck-coding/19514" target="_blank">Read-Search-Ask</a> 。编写自己的代码。 </section>
|
2018-10-10 18:03:03 -04:00
|
|
|
|
|
|
|
|
|
## Instructions
|
|
|
|
|
<section id="instructions">
|
|
|
|
|
</section>
|
|
|
|
|
|
|
|
|
|
## Tests
|
|
|
|
|
<section id='tests'>
|
|
|
|
|
|
|
|
|
|
```yml
|
|
|
|
|
tests:
|
|
|
|
|
- text: '<code>repeatStringNumTimes("*", 3)</code>应该返回<code>"***"</code> 。'
|
2020-02-18 01:40:55 +09:00
|
|
|
|
testString: assert(repeatStringNumTimes("*", 3) === "***");
|
2018-10-10 18:03:03 -04:00
|
|
|
|
- text: '<code>repeatStringNumTimes("abc", 3)</code>应该返回<code>"abcabcabc"</code> 。'
|
2020-02-18 01:40:55 +09:00
|
|
|
|
testString: assert(repeatStringNumTimes("abc", 3) === "abcabcabc");
|
2018-10-10 18:03:03 -04:00
|
|
|
|
- text: '<code>repeatStringNumTimes("abc", 4)</code>应返回<code>"abcabcabcabc"</code> 。'
|
2020-02-18 01:40:55 +09:00
|
|
|
|
testString: assert(repeatStringNumTimes("abc", 4) === "abcabcabcabc");
|
2018-10-10 18:03:03 -04:00
|
|
|
|
- text: '<code>repeatStringNumTimes("abc", 1)</code>应该返回<code>"abc"</code> 。'
|
2020-02-18 01:40:55 +09:00
|
|
|
|
testString: assert(repeatStringNumTimes("abc", 1) === "abc");
|
2018-10-10 18:03:03 -04:00
|
|
|
|
- text: '<code>repeatStringNumTimes("*", 8)</code>应该返回<code>"********"</code> 。'
|
2020-02-18 01:40:55 +09:00
|
|
|
|
testString: assert(repeatStringNumTimes("*", 8) === "********");
|
2018-10-10 18:03:03 -04:00
|
|
|
|
- text: '<code>repeatStringNumTimes("abc", -2)</code>应返回<code>""</code> 。'
|
2020-02-18 01:40:55 +09:00
|
|
|
|
testString: assert(repeatStringNumTimes("abc", -2) === "");
|
2018-10-10 18:03:03 -04:00
|
|
|
|
- text: 不应使用内置的<code>repeat()</code>方法
|
2020-02-18 01:40:55 +09:00
|
|
|
|
testString: assert(!/\.repeat/g.test(code));
|
2018-10-10 18:03:03 -04:00
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
</section>
|
|
|
|
|
|
|
|
|
|
## Challenge Seed
|
|
|
|
|
<section id='challengeSeed'>
|
|
|
|
|
|
|
|
|
|
<div id='js-seed'>
|
|
|
|
|
|
|
|
|
|
```js
|
|
|
|
|
function repeatStringNumTimes(str, num) {
|
|
|
|
|
// repeat after me
|
|
|
|
|
return str;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
repeatStringNumTimes("abc", 3);
|
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
</section>
|
|
|
|
|
|
|
|
|
|
## Solution
|
|
|
|
|
<section id='solution'>
|
|
|
|
|
|
|
|
|
|
```js
|
|
|
|
|
// solution required
|
|
|
|
|
```
|
|
|
|
|
</section>
|