W problem

This commit is contained in:
Kris Koishigawa
2019-03-11 16:21:45 +09:00
committed by mrugesh
parent a0e68a39a7
commit 723ee2cfa5

View File

@ -6,25 +6,12 @@ challengeType: 5
## Description
<section id='description'>
<p>
Even today, with proportional fonts and complex layouts, there are still
cases where you need to wrap text at a specified
column. The basic task is to wrap a paragraph of text in a simple way.
Example text:
</p>
<pre>
Wrap text using a more sophisticated algorithm such as the Knuth and Plass TeX algorithm.
If your language provides this, you get easy extra credit,
but you ''must reference documentation'' indicating that the algorithm
is something better than a simple minimimum length algorithm.
</pre>
<p>
Task:
Even today, with proportional fonts and complex layouts, there are still cases where you need to wrap text at a specified column. The basic task is to wrap a paragraph of text in a simple way.
</section>
Write a function that can wrap this text to any number of characters.
As an example, the text wrapped to 80 characters should look like the following:
</p>
## Instructions
<section id='instructions'>
Write a function that can wrap this text to any number of characters. As an example, the text wrapped to 80 characters should look like the following:
<pre>
Wrap text using a more sophisticated algorithm such as the Knuth and Plass TeX
algorithm. If your language provides this, you get easy extra credit, but you
@ -33,11 +20,6 @@ than a simple minimimum length algorithm.
</pre>
</section>
## Instructions
<section id='instructions'>
</section>
## Tests
<section id='tests'>
@ -66,7 +48,7 @@ tests:
<div id='js-seed'>
```js
function wrap (text, limit) {
function wrap(text, limit) {
return text;
}
```
@ -102,7 +84,7 @@ const firstRow42 = 'Wrap text using a more sophisticated';
```js
function wrap (text, limit) {
function wrap(text, limit) {
const noNewlines = text.replace('\n', '');
if (noNewlines.length > limit) {
// find the last space within limit