Created
February 14, 2023 09:53
-
-
Save lubien/eebfa3186d88bd555a6f1011fdff0e7f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// @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 ./door-policy.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 line of the | |
* poem, if this were said at the front door. | |
* | |
* @param {string} line | |
* @returns {string} | |
*/ | |
export function frontDoorResponse(line) { | |
return line[0] | |
} | |
/** | |
* Format the password for the front-door, given the response | |
* letters. | |
* | |
* @param {string} word the letters you responded with before | |
* @returns {string} the front door password | |
*/ | |
export function frontDoorPassword(word) { | |
return word[0].toUpperCase() + word.slice(1).toLowerCase() | |
} | |
/** | |
* Respond with the correct character, given the line of the | |
* poem, if this were said at the back door. | |
* | |
* @param {string} line | |
* @returns {string} | |
*/ | |
export function backDoorResponse(line) { | |
const trimmed = line.trim() | |
return trimmed[trimmed.length - 1] | |
} | |
/** | |
* Format the password for the back door, given the response | |
* letters. | |
* | |
* @param {string} word the letters you responded with before | |
* @returns {string} the back door password | |
*/ | |
export function backDoorPassword(word) { | |
return `${frontDoorPassword(word)}, please` | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment