|
| 1 | +// @ts-check |
| 2 | +// |
| 3 | +// ☝🏽 The line above enables type checking for this file. Various IDEs interpret |
| 4 | +// the @ts-check directive. It will give you helpful autocompletion on the web |
| 5 | +// and supported IDEs when implementing this exercise. You don't need to |
| 6 | +// understand types, JSDoc, or TypeScript in order to complete this JavaScript |
| 7 | +// exercise, and can completely ignore this comment block and directive. |
| 8 | +// |
| 9 | +// 👋🏽 Hi again! |
| 10 | +// |
| 11 | +// A quick reminder about exercise stubs: |
| 12 | +// |
| 13 | +// 💡 You're allowed to completely clear any stub before you get started. Often |
| 14 | +// we recommend using the stub, because they are already set-up correctly to |
| 15 | +// work with the tests, which you can find in ./door-policy.spec.js. |
| 16 | +// |
| 17 | +// 💡 You don't need to write JSDoc comment blocks yourself; it is not expected |
| 18 | +// in idiomatic JavaScript, but some companies and style-guides do enforce them. |
| 19 | +// |
| 20 | +// Good luck with that door policy! |
| 21 | + |
| 22 | +/** |
| 23 | + * Respond with the correct character, given the blurb, if this were said at |
| 24 | + * the front door. |
| 25 | + * |
| 26 | + * @param {string} blurb |
| 27 | + * @returns {string} |
| 28 | + */ |
| 29 | +export function frontDoorResponse(blurb) { |
| 30 | + return blurb[0]; |
| 31 | +} |
| 32 | + |
| 33 | +/** |
| 34 | + * Respond with the correct character, given the blurb, if this were said at |
| 35 | + * the back door. |
| 36 | + * |
| 37 | + * @param {string} blurb |
| 38 | + * @returns {string} |
| 39 | + */ |
| 40 | +export function backDoorResponse(blurb) { |
| 41 | + const trimmed = blurb.trim(); |
| 42 | + return trimmed[trimmed.length - 1]; |
| 43 | +} |
| 44 | + |
| 45 | +/** |
| 46 | + * Give the password for the front-door, given the responses. |
| 47 | + * |
| 48 | + * @param {string} responses the responses |
| 49 | + * @returns {string} the password |
| 50 | + */ |
| 51 | +export function frontDoorPassword(responses) { |
| 52 | + return capitalize(responses); |
| 53 | +} |
| 54 | + |
| 55 | +/** |
| 56 | + * Give the password for the back-door, given the responses. |
| 57 | + * |
| 58 | + * @param {string} responses the responses |
| 59 | + * @returns {string} the password |
| 60 | + */ |
| 61 | +export function backDoorPassword(responses) { |
| 62 | + return `${capitalize(responses)}, please`; |
| 63 | +} |
| 64 | + |
| 65 | +/** |
| 66 | + * Capitalizes a word, meaning only the first character is a capital, and the |
| 67 | + * remaining letters are lower case. |
| 68 | + * |
| 69 | + * @param {string} word |
| 70 | + * @returns {string} |
| 71 | + */ |
| 72 | +function capitalize(word) { |
| 73 | + return word[0].toUpperCase() + word.slice(1).toLowerCase(); |
| 74 | +} |
0 commit comments