Skip to content

[V3] Poetry Club Door Policy: fix everything around this exercise #1043

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 16 commits into from
Apr 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions concepts/strings/about.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,21 @@ Some of the most-used operations on strings are to check their `length` and to c
// => "I like cats"
```

You can find all the methods in the [MDN docs][mdn docs].
You can find all the methods in the [MDN docs][mdn-docs].

[mdn docs]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String#Instance_methods
## String interpolation

Strings in JavaScript support concatenation using [`+` and slight variations][https://developer.mozilla.org/en-us/docs/web/javascript/reference/global_objects/string#long_literal_strings] and interpolation using [string template literals][mdn-template-strings].

```javascript
const NUMBER_OF_CATS = 4;
const concatenation = 'I have ' + NUMBER_OF_CATS + ' cats';
// => "I have 4 cats"

const interpolation = `I have ${NUMBER_OF_CATS} cats`;
// => I have 4 cats
```

[mdn-docs]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String#Instance_methods
[mdn-template-strings]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals
[mdn-concatenation]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String#long_literal_strings
5 changes: 4 additions & 1 deletion concepts/strings/introduction.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Introduction

Strings are useful for holding data that can be represented in text form.
In JavaScript, create string literals using two single quotes (`'literal'`) or two double quotes (`"literal"`).

There are two ways to access an individual character in a string.

The first is the `charAt()` method:
Expand All @@ -10,7 +12,8 @@ The first is the `charAt()` method:
// => "a"
```

The other way is to treat a `string` as a list of characters, where individual characters correspond to a numerical index (starts at zero):
The other way is to treat a `string` as a list of characters, where individual characters correspond to a numerical index (starts at zero).
The indexer syntax (`[index]`) can then be used to acccess the character at a specific index:

```javascript
'cat'[1];
Expand Down
6 changes: 5 additions & 1 deletion concepts/strings/links.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
[
{
"url": "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String#Instance_methods",
"description": "mdn docs"
"description": "MDN: Strings"
},
{
"url": "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals",
"description": "MDN: Template literals"
}
]
5 changes: 3 additions & 2 deletions config.json
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,8 @@
"status": "beta"
},
{
"slug": "strings",
"slug": "poetry-club-door-policy",
"name": "Poetry Club Door Policy",
"uuid": "39549583-1889-490a-bf98-ffb2e0aefe44",
"concepts": ["strings"],
"prerequisites": ["basics"],
Expand Down Expand Up @@ -1595,7 +1596,7 @@
"uuid": "7d5c1533-c7cf-418e-b0f2-080da1e5bdc5",
"slug": "strings",
"name": "Strings",
"blurb": "TODO: add blurb for strings concept"
"blurb": "Strings are useful for holding data that can be represented in text form. "
},
{
"uuid": "a8cdc468-c950-43d7-a1b8-99a5e0de651a",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,25 @@

## 1. Get the first letter of a sentence

- Any `string` in JavaScript has two methods to access characters at a certain
position: a regular method `.method(position)`, and using `array` style
indexers `[position]`.
- Any `string` in JavaScript has two methods to access characters at a certain position: a regular method `.method(position)`, and using `array` style indexers `[position]`.
- `.charAt(position)` will get the character at `position`.

## 2. Capitalize a word

- Capitalization means having a single Uppercase character, followed by
lowercase characters.
- There are two methods to take a part of a string (for example, everything
except the first character).
- Capitalization means having a single _Uppercase_ character, followed by _lowercase_ characters.
- There are two methods to take a portion of a string (for example, everything except the first character).
- `.slice(position)` can slice up a string at a position.

## 3. Get the last letter of a sentence

- This is similar to getting the first letter, except that it might be
preferable to use the number of characters in the string to find the position
of the last character.
- This is similar to getting the first letter, except that it might be preferable to use the number of characters in the string to find the position of the last character.
- The number of characters in a string is given by its `.length` property.

## 4. Trim a sentence

- `.trim()` method is available on the `String.prototype` (methods
that work on `string`).
- `.trim()` method is available on the `String.prototype` (methods that work on `string`).

## 5. Be polite

- There are various ways to concatenate a `string` in JavaScript. It's also
possible to use `string` templating.
- Use `+ other` or `.concat(other)` to concatenate, use backticks (`) to build
a _string template literal_.
- There are various ways to concatenate a `string` in JavaScript. It's also possible to use `string` templating.
- Use `+ other` or `.concat(other)` to concatenate, use backticks (`) to build a _string template literal_.
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
# Instructions

A new poetry club has opened in town, and you're thinking of attending. Because
there have been incidents in the past, the club has a very specific door policy
which you'll need to master, before attempting entry.
A new poetry club has opened in town, and you're thinking of attending.
Because there have been incidents in the past, the club has a very specific door policy which you'll need to master, before attempting entry.

There are two doors at the poetry club, both are guarded. In order to gain
entry, you'll need to work out the password of that day:
There are two doors at the poetry club, both are guarded.
In order to gain entry, you'll need to work out the password of that day:

## Front door

Expand All @@ -14,9 +13,7 @@ entry, you'll need to work out the password of that day:
2. The guard will tell you all the letters you've responded with at once;
- You need to format the letters as a capitalised word.

For example, one of their favourite writers is Michael Lockwood, who's written
the following _acrostic_ poem, which means that the first letter of each
sentence form a word:
For example, one of their favourite writers is Michael Lockwood, who's written the following _acrostic_ poem, which means that the first letter of each sentence form a word:

```text
Stands so high
Expand All @@ -26,26 +23,22 @@ Reins and harness
Eager to leave
```

When the guard recites **Stands so high**, you'll respond **S**, when the guard
recites **Huge hooves too**, you'll respond **H**.
When the guard recites **Stands so high**, you'll respond **S**, when the guard recites **Huge hooves too**, you'll respond **H**.

Finally the password you write down is `Shire`, and you'll get in.

## Back door

In the back of the club you'll find the most renowned poets, which is like the
VIP area. Because this is not for everyone, the back door process is a bit more
convoluted.
In the back of the club you'll find the most renowned poets, which is like the VIP area.
Because this is not for everyone, the back door process is a bit more convoluted.

1. The guard will recite a poem, one line at the time;
- You will have to respond with the appropriate letter.
2. The guard will tell you all the letters you've responded with at once, _but
there are sometimes spaces after each sentence_:
2. The guard will tell you all the letters you've responded with at once, _but there are sometimes spaces after each sentence_:
- You need to format the letters as a capitalised word
- and ask nicely, by appending `, please`

For example, the poem mentioned before is also _telestich_, which means that
the last letter of each sentence form a word:
For example, the poem mentioned before is also _telestich_, which means that the last letter of each sentence form a word:

```text
Stands so high
Expand All @@ -55,11 +48,9 @@ Reins and harness
Eager to leave
```

When the guard recites **Stands so high**, you'll respond **h**, when the guard
recites **Huge hooves too**, you'll respond **o**.
When the guard recites **Stands so high**, you'll respond **h**, when the guard recites **Huge hooves too**, you'll respond **o**.

Finally the password you write down is `Horse, please`, and you can party
with the renowned poets.
Finally the password you write down is `Horse, please`, and you can party with the renowned poets.

## Tasks

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
"authors": ["SleeplessByte"],
"contributors": ["hayashi-ay"],
"files": {
"solution": ["strings.js"],
"test": ["strings.spec.js"],
"solution": ["door-policy.js"],
"test": ["door-policy.spec.js"],
"exemplar": [".meta/exemplar.js"]
},
"forked_from": []
Expand Down
31 changes: 31 additions & 0 deletions exercises/concept/poetry-club-door-policy/.meta/design.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Design

## Learning objectives

- String substrings (first, last letter)
- String casing (Word capitalization, normalisation).
- String concatenation

## Out of scope

- Codepoints

## Concepts

- `strings`

## Prerequisites

- `basics`

## Analyzer

This exercise could benefit from the following rules added to the the [analyzer][analyzer]:

- Verify that the `frontDoorResponse` function uses `[0]` or `charAt(0)`. `slice(0, 1)` / `substring(0, 1)` works but is not optimal.
- Verify that the `backDoorResponse` function uses `trim()` or `trimEnd()`, and `[n-1]` or `charAt(n-1)` together with `.length`.
- Verify that the `frontDoorPassword` function uses a helper (like `capitalize`).
- Verify that the `backDoorPassword` function uses a helper (like `capitalize`), and builds the string using `+ ', please` or `${}, please`.
- Verify that the helper (`capitalize`) uses `toUpperCase()` and `slice(1).toLowerCase()`, or `substring(1).toLowerCase()`

[analyzer]: https://github.com/exercism/javascript-analyzer
Original file line number Diff line number Diff line change
@@ -1,3 +1,24 @@
// @ts-check
//
// ☝🏽 The line above enables type checking for this file. Various IDEs interpret
// the @ts-check directive. It will give you helpful autocompletion on the web
// and supported IDEs when implementing this exercise. You don't need to
// understand types, JSDoc, or TypeScript in order to complete this JavaScript
// exercise, and can completely ignore this comment block and directive.
//
// 👋🏽 Hi again!
//
// A quick reminder about exercise stubs:
//
// 💡 You're allowed to completely clear any stub before you get started. Often
// we recommend using the stub, because they are already set-up correctly to
// work with the tests, which you can find in ./freelancer-rates.spec.js.
//
// 💡 You don't need to write JSDoc comment blocks yourself; it is not expected
// in idiomatic JavaScript, but some companies and style-guides do enforce them.
//
// Good luck with that door policy!

/**
* Respond with the correct character, given the blurb, if this were said at
* the front door.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,23 @@
// @ts-check
//
// The line above enables type checking for this file. Various IDEs interpret
// the @ts-check directive. It will give you helpful autocompletion when
// implementing this exercise. You don't need to understand it in order to
// benefit from it.
// ☝🏽 The line above enables type checking for this file. Various IDEs interpret
// the @ts-check directive. It will give you helpful autocompletion on the web
// and supported IDEs when implementing this exercise. You don't need to
// understand types, JSDoc, or TypeScript in order to complete this JavaScript
// exercise, and can completely ignore this comment block and directive.
//
// In your own projects, files, and code, you can play with @ts-check as well.
// 👋🏽 Hi again!
//
// A quick reminder about exercise stubs:
//
// 💡 You're allowed to completely clear any stub before you get started. Often
// we recommend using the stub, because they are already set-up correctly to
// work with the tests, which you can find in ./freelancer-rates.spec.js.
//
// 💡 You don't need to write JSDoc comment blocks yourself; it is not expected
// in idiomatic JavaScript, but some companies and style-guides do enforce them.
//
// Good luck with that door policy!

/**
* Respond with the correct character, given the blurb, if this were said at
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
backDoorResponse as backDoorPatron,
frontDoorPassword,
backDoorPassword,
} from './strings';
} from './door-policy';

class Poem {
constructor(poem) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
"name": "@exercism/javascript-strings",
"name": "@exercism/javascript-poetry-club-door-policy",
"description": "Exercism concept exercise on strings",
"author": "Derk-Jan Karrenbeld <derk-jan+github@karrenbeld.info>",
"private": true,
"repository": {
"type": "git",
"url": "https://github.com/exercism/javascript",
"directory": "languages/javascript/exercises/concept/strings"
"directory": "exercises/concept/poetry-club-door-policy"
},
"devDependencies": {
"@babel/cli": "^7.13.14",
Expand Down