freeCodeCamp/curriculum/challenges/chinese/08-coding-interview-prep/rosetta-code/word-wrap.chinese.md

79 lines
2.3 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

---
title: Word wrap
id: 594810f028c0303b75339ad4
challengeType: 5
videoUrl: ''
localeTitle: 自动换行
---
## Description
<section id="description"><p>即使在今天,使用比例字体和复杂布局,仍然存在需要在指定列处包装文本的情况。基本任务是以简单的方式包装一段文本。示例文字: </p><pre>使用更复杂的算法如Knuth和Plass TeX算法包装文本。
如果您的语言提供此功能,您可以获得额外的信用,
但你“必须参考文档”表明该算法
比简单的最小长度算法更好。
</pre><p>任务: </p><pre> <code>Write a function that can wrap this text to any number of characters.</code> </pre><p>例如包装为80个字符的文本应如下所示 </p><p></p><pre>使用更复杂的算法如Knuth和Plass TeX包装文本
算法。如果您的语言提供此功能,您可以轻松获得额外的功劳
必须参考文档,表明该算法更好
而不是简单的最小长度算法。
</pre></section>
## Instructions
<section id="instructions">
</section>
## Tests
<section id='tests'>
```yml
tests:
- text: ''
testString: 'assert.equal(typeof wrap, "function", "wrap must be a function.");'
- text: ''
testString: 'assert.equal(typeof wrap("abc", 10), "string", "wrap must return a string.");'
- text: wrap80必须返回4行。
testString: 'assert(wrapped80.split("\n").length === 4, "wrap(80) must return 4 lines.");'
- text: 你的<code>wrap</code>函数应该返回我们期望的文本
testString: 'assert.equal(wrapped80.split("\n")[0], firstRow80, "Your <code>wrap</code> function should return our expected text");'
- text: wrap42必须返回7行。
testString: 'assert(wrapped42.split("\n").length === 7, "wrap(42) must return 7 lines.");'
- text: 你的<code>wrap</code>函数应该返回我们期望的文本
testString: 'assert.equal(wrapped42.split("\n")[0], firstRow42, "Your <code>wrap</code> function should return our expected text");'
```
</section>
## Challenge Seed
<section id='challengeSeed'>
<div id='js-seed'>
```js
function wrap (text, limit) {
return text;
}
```
</div>
### After Test
<div id='js-teardown'>
```js
console.info('after the test');
```
</div>
</section>
## Solution
<section id='solution'>
```js
// solution required
```
</section>