fix(curriculum): improve description and tests description (#42465)
* fix: make tests descriptions more explicit * fix: clarify function input * fix: clarify output of function, add example
This commit is contained in:
@ -8,35 +8,43 @@ dashedName: align-columns
|
|||||||
|
|
||||||
# --description--
|
# --description--
|
||||||
|
|
||||||
Given a text file of many lines, where fields within a line are delineated by a single `$` character, write a program that aligns each column of fields by ensuring that words in each column are separated by at least one space. Further, allow for each word in a column to be either left justified, right justified, or center justified within its column.
|
Given an array of many lines, where fields within a line are delineated by a single `$` character, write a program that aligns each column of fields by ensuring that words in each column are separated by at least one space. Further, allow for each word in a column to be either left justified, right justified, or center justified within its column.
|
||||||
|
|
||||||
# --instructions--
|
# --instructions--
|
||||||
|
|
||||||
Use the following text to test your programs:
|
Use the following text to test your programs:
|
||||||
|
|
||||||
<pre>
|
```js
|
||||||
Given$a$text$file$of$many$lines
|
const testText = [
|
||||||
where$fields$within$a$line$
|
'Given$a$text$file$of$many$lines',
|
||||||
are$delineated$by$a$single$'dollar'$character
|
'where$fields$within$a$line$',
|
||||||
write$a$program
|
'are$delineated$by$a$single$"dollar"$character',
|
||||||
that$aligns$each$column$of$fields
|
'write$a$program',
|
||||||
by$ensuring$that$words$in$each$
|
'that$aligns$each$column$of$fields',
|
||||||
column$are$separated$by$at$least$one$space.
|
'by$ensuring$that$words$in$each$',
|
||||||
Further,$allow$for$each$word$in$a$column$to$be$either$left$
|
'column$are$separated$by$at$least$one$space.',
|
||||||
justified,$right$justified
|
'Further,$allow$for$each$word$in$a$column$to$be$either$left$',
|
||||||
or$center$justified$within$its$column.
|
'justified,$right$justified',
|
||||||
</pre>
|
'or$center$justified$within$its$column.'
|
||||||
|
];
|
||||||
|
```
|
||||||
|
|
||||||
**Note that:**
|
**Note that:**
|
||||||
|
|
||||||
<ul>
|
- The example input texts lines may, or may not, have trailing dollar characters.
|
||||||
<li>The example input texts lines may, or may not, have trailing dollar characters.</li>
|
- All columns should share the same alignment.
|
||||||
<li>All columns should share the same alignment.</li>
|
- Consecutive space characters produced adjacent to the end of lines are insignificant for the purposes of the task.
|
||||||
<li>Consecutive space characters produced adjacent to the end of lines are insignificant for the purposes of the task.</li>
|
- Output text will be viewed in a mono-spaced font on a plain text editor or basic terminal. Lines in it should be joined using new line character (`\n`).
|
||||||
<li>Output text will be viewed in a mono-spaced font on a plain text editor or basic terminal.</li>
|
- The minimum space between columns should be computed from the text and not hard-coded.
|
||||||
<li>The minimum space between columns should be computed from the text and not hard-coded.</li>
|
- It is not a requirement to add separating characters between or around columns.
|
||||||
<li>It is not a requirement to add separating characters between or around columns.</li>
|
|
||||||
</ul>
|
For example, one of the lines from the `testText`, after jusitifing to the right, left and center respectivelly:
|
||||||
|
|
||||||
|
```js
|
||||||
|
' column are separated by at least one space.\n'
|
||||||
|
'column are separated by at least one space.\n'
|
||||||
|
' column are separated by at least one space.\n'
|
||||||
|
```
|
||||||
|
|
||||||
# --hints--
|
# --hints--
|
||||||
|
|
||||||
@ -46,22 +54,22 @@ or$center$justified$within$its$column.
|
|||||||
assert(typeof formatText === 'function');
|
assert(typeof formatText === 'function');
|
||||||
```
|
```
|
||||||
|
|
||||||
`formatText` with the above input and "right" justification should produce the following:
|
`formatText(testText, 'right')` should produce text with columns justified to the right.
|
||||||
|
|
||||||
```js
|
```js
|
||||||
assert.strictEqual(formatText(testInput, 'right'), rightAligned);
|
assert.strictEqual(formatText(_testText, 'right'), rightAligned);
|
||||||
```
|
```
|
||||||
|
|
||||||
`formatText` with the above input and "left" justification should produce the following:
|
`formatText(testText, 'left')` should produce text with columns justified to the left.
|
||||||
|
|
||||||
```js
|
```js
|
||||||
assert.strictEqual(formatText(testInput, 'left'), leftAligned);
|
assert.strictEqual(formatText(_testText, 'left'), leftAligned);
|
||||||
```
|
```
|
||||||
|
|
||||||
`formatText` with the above input and "center" justification should produce the following:
|
`formatText(testText, 'center')` should produce text with columns justified to the center.
|
||||||
|
|
||||||
```js
|
```js
|
||||||
assert.strictEqual(formatText(testInput, 'center'), centerAligned);
|
assert.strictEqual(formatText(_testText, 'center'), centerAligned);
|
||||||
```
|
```
|
||||||
|
|
||||||
# --seed--
|
# --seed--
|
||||||
@ -69,10 +77,10 @@ assert.strictEqual(formatText(testInput, 'center'), centerAligned);
|
|||||||
## --after-user-code--
|
## --after-user-code--
|
||||||
|
|
||||||
```js
|
```js
|
||||||
const testInput = [
|
const _testText = [
|
||||||
'Given$a$text$file$of$many$lines',
|
'Given$a$text$file$of$many$lines',
|
||||||
'where$fields$within$a$line$',
|
'where$fields$within$a$line$',
|
||||||
'are$delineated$by$a$single$\"dollar\"$character',
|
'are$delineated$by$a$single$"dollar"$character',
|
||||||
'write$a$program',
|
'write$a$program',
|
||||||
'that$aligns$each$column$of$fields$',
|
'that$aligns$each$column$of$fields$',
|
||||||
'by$ensuring$that$words$in$each$',
|
'by$ensuring$that$words$in$each$',
|
||||||
@ -119,7 +127,11 @@ const centerAligned = ' Given a text file of many
|
|||||||
## --seed-contents--
|
## --seed-contents--
|
||||||
|
|
||||||
```js
|
```js
|
||||||
const testArr = [
|
function formatText(input, justification) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
const testText = [
|
||||||
'Given$a$text$file$of$many$lines',
|
'Given$a$text$file$of$many$lines',
|
||||||
'where$fields$within$a$line$',
|
'where$fields$within$a$line$',
|
||||||
'are$delineated$by$a$single$"dollar"$character',
|
'are$delineated$by$a$single$"dollar"$character',
|
||||||
@ -131,28 +143,11 @@ const testArr = [
|
|||||||
'justified,$right$justified',
|
'justified,$right$justified',
|
||||||
'or$center$justified$within$its$column.'
|
'or$center$justified$within$its$column.'
|
||||||
];
|
];
|
||||||
|
|
||||||
function formatText(input, justification) {
|
|
||||||
|
|
||||||
}
|
|
||||||
```
|
```
|
||||||
|
|
||||||
# --solutions--
|
# --solutions--
|
||||||
|
|
||||||
```js
|
```js
|
||||||
const testArr = [
|
|
||||||
'Given$a$text$file$of$many$lines',
|
|
||||||
'where$fields$within$a$line$',
|
|
||||||
'are$delineated$by$a$single$"dollar"$character',
|
|
||||||
'write$a$program',
|
|
||||||
'that$aligns$each$column$of$fields$',
|
|
||||||
'by$ensuring$that$words$in$each$',
|
|
||||||
'column$are$separated$by$at$least$one$space.',
|
|
||||||
'Further,$allow$for$each$word$in$a$column$to$be$either$left$',
|
|
||||||
'justified,$right$justified',
|
|
||||||
'or$center$justified$within$its$column.'
|
|
||||||
];
|
|
||||||
|
|
||||||
String.prototype.repeat = function (n) { return new Array(1 + parseInt(n)).join(this); };
|
String.prototype.repeat = function (n) { return new Array(1 + parseInt(n)).join(this); };
|
||||||
|
|
||||||
function formatText(input, justification) {
|
function formatText(input, justification) {
|
||||||
|
Reference in New Issue
Block a user