Skip to content

Commit 908e708

Browse files
Apply suggestions from code review
Co-authored-by: Derk-Jan Karrenbeld <derk-jan+github@karrenbeld.info>
1 parent b382107 commit 908e708

1 file changed

Lines changed: 28 additions & 8 deletions

File tree

exercises/concept/poetry-club-door-policy/.approaches/introduction.md

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
# Introduction
22

3-
There are various ways to solve each part of Poetry Club Door Policy. A commonality between most of the parts is needing to get a character from the provided string.
3+
There are various ways to solve each part of Poetry Club Door Policy.
4+
A commonality between most of the parts is needing to get a character from the provided string.
45

56
There are multiple ways to do this, one of which is the standard way of using `[index]` access.
67

78
One other way is to use [`charAt`][mdn-char-at], which is the same as `[index]` access for most purposes.
89

910
Another method is [`at`][mdn-at], which is the same as `[index]` access, except it accepts negative numbers.
10-
1111
A negative number will count backwards from the end of the string, unlike positive numbers, which count forwards from the start.
1212

13-
In addition, [`substring`][mdn-substring] and [`slice`][mdn-slice] can be used. These string methods are normally used to get portions of strings, rather than a single character.
13+
In addition, [`substring`][mdn-substring] and [`slice`][mdn-slice] can be used.
14+
These string methods are normally used to get portions of strings, rather than a single character.
1415

1516
An important distiction is that `slice` accepts negative numbers like `at` does, but `substring` does not.
1617

@@ -36,20 +37,38 @@ export function frontDoorPassword(word) {
3637
}
3738
```
3839

39-
This approach uses [`toLocaleUpperCase`][mdn-to-locale-upper-case] and [`toLocaleLowerCase`][mdn-to-locale-lower-case], which are very similar to `toUpperCase` and `toLowerCase`.
40+
This approach uses [`toLocaleUpperCase`][mdn-to-locale-upper-case] and [`toLocaleLowerCase`][mdn-to-locale-lower-case], which are very similar to `toUpperCase` and `toLowerCase`, but work with either the current locale or a given locale, which can be specified as an argument.
41+
This approach is necessary when the language locale has a non-standard mapping between lower and uppercase.
42+
43+
```javascript
44+
const str = "istanbul";
45+
46+
str.toUpperCase()
47+
// => 'ISTANBUL'
48+
str.toLocaleUpperCase('en-US')
49+
// => 'ISTANBUL'
4050

41-
When using `toLocaleUpperCase` or `toLocaleLowerCase`, you can specify a locale string as an argument and the output will be adjusted to that locale.
51+
str.toLocaleUpperCase('tr')
52+
// => 'İSTANBUL'
53+
```
4254

4355
### Approach: `String.fromCharCode` and `charCodeAt`
4456

4557
```js
4658
export function frontDoorPassword(word) {
4759
let charCode = word.charCodeAt(0);
48-
if (charCode >= 97) charCode -= 32;
60+
if (charCode >= 97) {
61+
charCode -= 32;
62+
}
63+
4964
let password = String.fromCharCode(charCode);
65+
5066
for (let index = 1; index < word.length; index++) {
5167
charCode = word.charCodeAt(index);
52-
if (charCode <= 90) charCode += 32;
68+
if (charCode <= 90) {
69+
charCode += 32;
70+
}
71+
5372
password += String.fromCharCode(charCode);
5473
}
5574
return password;
@@ -126,7 +145,8 @@ export function backDoorResponse(line) {
126145
}
127146
```
128147

129-
This approach does not trim whitespace. Instead, it uses a [for loop][mdn-for] to return the first character that is not a space from the end of the string.
148+
This approach does not trim whitespace.
149+
Instead, it uses a [for loop][mdn-for] to return the first character that is not a space from the end of the string.
130150

131151
[mdn-char-at]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/charAt
132152
[mdn-at]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/at

0 commit comments

Comments
 (0)