-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdoor-policy.js
66 lines (62 loc) · 2.02 KB
/
door-policy.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
// @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) {
let lowercaseword = word.toLowerCase()
return lowercaseword[0].toUpperCase() + lowercaseword.slice(1)
}
/**
* 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) {
let password = line.trim()
return password[password.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 word.toLowerCase().replace(word[0], word[0].toUpperCase()) + ", please"
}