Skip to content

Commit b6c7a71

Browse files
committed
fixes
1 parent d67c04c commit b6c7a71

File tree

3 files changed

+11
-13
lines changed
  • 1-js/05-data-types/05-array-methods
  • 2-ui/2-events/01-introduction-browser-events
  • 5-regular-expressions/08-regexp-greedy-and-lazy

3 files changed

+11
-13
lines changed

1-js/05-data-types/05-array-methods/article.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -517,7 +517,7 @@ Here we get a sum of array in one line:
517517
```js run
518518
let arr = [1, 2, 3, 4, 5]
519519

520-
let result = arr.reduce((sum, current) => sum + current), 0);
520+
let result = arr.reduce((sum, current) => sum + current, 0);
521521

522522
alert(result); // 15
523523
```

2-ui/2-events/01-introduction-browser-events/article.md

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,7 @@ For instance:
388388
</script>
389389
```
390390

391-
In other words, when `addEventListener` receives and object as the handler, it calls `object.handleEvent(event)` in case of an event.
391+
In other words, when `addEventListener` receives an object as the handler, it calls `object.handleEvent(event)` in case of an event.
392392

393393
We could also use a class for that:
394394

@@ -418,9 +418,9 @@ We could also use a class for that:
418418
</script>
419419
```
420420

421-
Here the same object handles both events. Please note that we need to explicitly setup the listeners. The `menu` object only gets `mousedown` and `mouseup` here, not any other types of events.
421+
Here the same object handles both events. Please note that we need to explicitly setup the events to listen using `addEventListener`. The `menu` object only gets `mousedown` and `mouseup` here, not any other types of events.
422422

423-
The method `handleEvent` does not have to handle everything by itself. It can call the corresponding event-specific instead, like this:
423+
The method `handleEvent` does not have to do all the job by itself. It can call other event-specific methods instead, like this:
424424

425425
```html run
426426
<button id="elem">Click me</button>
@@ -456,16 +456,14 @@ There are 3 ways to assign event handlers:
456456

457457
1. HTML attribute: `onclick="..."`.
458458
2. DOM property: `elem.onclick = function`.
459-
3. Methods `elem.addEventListener(event, handler[, phase])`, to remove: `removeEventListener`.
459+
3. Methods: `elem.addEventListener(event, handler[, phase])` to add, `removeEventListener` to remove.
460460

461461
HTML attributes are used sparingly, because JavaScript in the middle of an HTML tag looks a little bit odd and alien. Also can't write lots of code in there.
462462

463463
DOM properties are ok to use, but we can't assign more than one handler of the particular event. In many cases that limitation is not pressing.
464464

465-
The last way is the most flexible, but it is also the longest to write. There are few events that only work with it, for instance `transtionend` and `DOMContentLoaded` (to be covered).
465+
The last way is the most flexible, but it is also the longest to write. There are few events that only work with it, for instance `transtionend` and `DOMContentLoaded` (to be covered). Also `addEventListener` supports objects as event handlers. In that case the method `handleEvent` is called in case of the event.
466466

467-
Also `addEventListener` supports objects as event handlers. In that case the method `handleEvent` is called in case of the event.
468-
469-
When a handler is called, it gets an event object as the first argument that contains the details about what's happened.
467+
No matter how you assign the handler -- it gets an event object as the first argument. That object contains the details about what's happened.
470468

471469
We'll learn more about events in general and about different types of events in the next chapters.

5-regular-expressions/08-regexp-greedy-and-lazy/article.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,20 +39,20 @@ That can be described as "greediness is the cause of all evil".
3939
To find a match, the regular expression engine uses the following algorithm:
4040

4141
- For every position in the string
42-
- Match the pattern symbol-by-symbol using classes and quantifiers.
42+
- Match the pattern at that position.
4343
- If there's no match, go to the next position.
4444

4545
These common words do not make it obvious why the regexp fails, so let's elaborate how the search works for the pattern `pattern:".+"`.
4646

4747
1. The first pattern character is a quote `pattern:"`.
4848

49-
The regular expression engine tries to find it on 0-th position of the source string, but there's `subject:a` there, so no match.
49+
The regular expression engine tries to find it at the zero position of the source string `subject:a "witch" and her "broom" is one`, but there's `subject:a` there, so there's immediately no match.
5050

51-
Then it advances: goes to the 1st, 2nd positions in the source string and tries to find the pattern there, and finally finds the quote at the 3rd position:
51+
Then it advances: goes to the next positions in the source string and tries to find the first character of the pattern there, and finally finds the quote at the 3rd position:
5252

5353
![](witch_greedy1.png)
5454

55-
2. The quote is detected, and then the engine tries to find a match for the rest of the pattern.
55+
2. The quote is detected, and then the engine tries to find a match for the rest of the pattern. It tries to see if the rest of the subject string conforms to `pattern:.+"`.
5656

5757
In our case the next pattern character is `pattern:.` (a dot). It denotes "any character except a newline", so the next string letter `match:'w'` fits:
5858

0 commit comments

Comments
 (0)