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 ## Description
<section id='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.
Even today, with proportional fonts and complex layouts, there are still </section>
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:
Write a function that can wrap this text to any number of characters. ## Instructions
<section id='instructions'>
As an example, the text wrapped to 80 characters should look like the following: 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>
<pre> <pre>
Wrap text using a more sophisticated algorithm such as the Knuth and Plass TeX 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 algorithm. If your language provides this, you get easy extra credit, but you
@ -33,11 +20,6 @@ than a simple minimimum length algorithm.
</pre> </pre>
</section> </section>
## Instructions
<section id='instructions'>
</section>
## Tests ## Tests
<section id='tests'> <section id='tests'>
@ -66,7 +48,7 @@ tests:
<div id='js-seed'> <div id='js-seed'>
```js ```js
function wrap (text, limit) { function wrap(text, limit) {
return text; return text;
} }
``` ```
@ -102,7 +84,7 @@ const firstRow42 = 'Wrap text using a more sophisticated';
```js ```js
function wrap (text, limit) { function wrap(text, limit) {
const noNewlines = text.replace('\n', ''); const noNewlines = text.replace('\n', '');
if (noNewlines.length > limit) { if (noNewlines.length > limit) {
// find the last space within limit // find the last space within limit