Skip to content

Commit 9f6288b

Browse files
committed
Integrate tech editing for Chapter 9
1 parent 33ee6b8 commit 9f6288b

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

09_regexp.md

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -154,12 +154,12 @@ as `[0-9]`.
154154
| `\S` | A nonwhitespace character
155155
| `.` | Any character except for newline
156156

157-
So you could match a ((date)) and ((time)) format like 30-01-2003
157+
So you could match a ((date)) and ((time)) format like 01-30-2003
158158
15:20 with the following expression:
159159

160160
```
161161
let dateTime = /\d\d-\d\d-\d\d\d\d \d\d:\d\d/;
162-
console.log(dateTime.test("30-01-2003 15:20"));
162+
console.log(dateTime.test("01-30-2003 15:20"));
163163
// → true
164164
console.log(dateTime.test("30-jan-2003 15:20"));
165165
// → false
@@ -255,7 +255,7 @@ is also slightly easier to decipher.
255255

256256
```
257257
let dateTime = /\d{1,2}-\d{1,2}-\d{4} \d{1,2}:\d{2}/;
258-
console.log(dateTime.test("30-1-2003 8:45"));
258+
console.log(dateTime.test("1-30-2003 8:45"));
259259
// → true
260260
```
261261

@@ -424,8 +424,8 @@ millisecond count by creating a new `Date` object and calling
424424

425425
Date objects provide methods like `getFullYear`, `getMonth`,
426426
`getDate`, `getHours`, `getMinutes`, and `getSeconds` to extract their
427-
components. Besides `getFullYear`, there's also `getYear`, which gives
428-
you a rather useless two-digit year value (such as `93` or `14`).
427+
components. Besides `getFullYear` there's also `getYear`, which gives
428+
you the year minus 1900 (`98` or `119`), and is mostly useless.
429429

430430
{{index "capture group", "getDate function"}}
431431

@@ -434,11 +434,11 @@ interested in, we can now create a date object from a string.
434434

435435
```
436436
function getDate(string) {
437-
let [_, day, month, year] =
437+
let [_, month, day, year] =
438438
/(\d{1,2})-(\d{1,2})-(\d{4})/.exec(string);
439439
return new Date(year, month - 1, day);
440440
}
441-
console.log(getDate("30-1-2003"));
441+
console.log(getDate("1-30-2003"));
442442
// → Thu Jan 30 2003 00:00:00 GMT+0100 (CET)
443443
```
444444

@@ -1036,8 +1036,9 @@ usually called an _INI_ file) are as follows:
10361036
- Anything else is invalid.
10371037

10381038
Our task is to convert a string like this into an object whose
1039-
properties hold strings for sectionless settings and sub-objects for
1040-
sections, with those sub-objects holding the section's settings.
1039+
properties hold strings for settings written before the first
1040+
section header and sub-objects for sections, with those sub-objects
1041+
holding the section's settings.
10411042

10421043
{{index "carriage return", "line break", "newline character"}}
10431044

code/solutions/09_3_numbers_again.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// Fill in this regular expression.
2-
let number = /^(\+|-|)(\d+(\.\d*)?|\.\d+)([eE](\+|-|)\d+)?$/;
2+
let number = /^[+\-]?(\d+(\.\d*)?|\.\d+)([eE][+\-]?\d+)?$/;
33

44
// Tests:
55
for (let str of ["1", "-1", "+15", "1.55", ".5", "5.",
@@ -14,4 +14,3 @@ for (let str of ["1a", "+-1", "1.2.3", "1+1", "1e4.5",
1414
console.log(`Incorrectly accepted '${str}'`);
1515
}
1616
}
17-

0 commit comments

Comments
 (0)