Skip to content

Commit 9e8c6a4

Browse files
committed
Merge branch 'master' of github.com:javascript-tutorial/en.javascript.info into sync-b52aa942
2 parents 91ce4cc + b52aa94 commit 9e8c6a4

File tree

11 files changed

+56
-31
lines changed

11 files changed

+56
-31
lines changed

1-js/02-first-steps/08-operators/3-primitive-conversions-questions/solution.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ true + false = 1
1010
"4" - 2 = 2
1111
"4px" - 2 = NaN
1212
7 / 0 = Infinity
13-
" -9 " + 5 = " -9 5" // (3)
14-
" -9 " - 5 = -14 // (4)
13+
" -9 " + 5 = " -9 5" // (3)
14+
" -9 " - 5 = -14 // (4)
1515
null + 1 = 1 // (5)
1616
undefined + 1 = NaN // (6)
1717
" \t \n" - 2 = -2 // (7)

1-js/02-first-steps/12-nullish-coalescing-operator/article.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,11 @@ alert(height || 100); // 100
6060
alert(height ?? 100); // 0
6161
```
6262
63-
Here, `height || 100` treats zero height as unset, same as `null`, `undefined` or any other falsy value. So zero becames `100`.
63+
Here, `height || 100` treats zero height as unset, same as `null`, `undefined` or any other falsy value. So the result is `100`.
6464
65-
The `height ?? 100` returns `100` only if `height` is exactly `null` or `undefined`. So zero remains "as is".
65+
The `height ?? 100` returns `100` only if `height` is exactly `null` or `undefined`. So the `alert` shows the height value `0` "as is".
6666
67-
Which behavior is better depends on a particular use case. When zero height is a valid value, that we shouldn't touch, then `??` is preferrable.
67+
Which behavior is better depends on a particular use case. When zero height is a valid value, then `??` is preferrable.
6868
6969
## Precedence
7070

1-js/03-code-quality/04-ninja-code/article.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ The Dao hides in wordlessness. Only the Dao is well begun and well
4343
completed.
4444
```
4545

46-
Another way to code faster is to use single-letter variable names everywhere. Like `a`, `b` or `c`.
46+
Another way to code shorter is to use single-letter variable names everywhere. Like `a`, `b` or `c`.
4747

4848
A short variable disappears in the code like a real ninja in the forest. No one will be able to find it using "search" of the editor. And even if someone does, they won't be able to "decipher" what the name `a` or `b` means.
4949

1-js/05-data-types/10-destructuring-assignment/article.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ alert(`${guest} ${admin}`); // Pete Jane (successfully swapped!)
138138
Here we create a temporary array of two variables and immediately destructure it in swapped order.
139139

140140
We can swap more than two variables this way.
141-
```
141+
142142

143143
### The rest '...'
144144

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
function byField(fieldName){
2+
return (a, b) => a[fieldName] > b[fieldName] ? 1 : -1;
3+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
function byField(fieldName){
2+
3+
// Your code goes here.
4+
5+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
describe("byField", function(){
2+
3+
let users = [
4+
{ name: "John", age: 20, surname: "Johnson" },
5+
{ name: "Pete", age: 18, surname: "Peterson" },
6+
{ name: "Ann", age: 19, surname: "Hathaway" },
7+
];
8+
9+
it("sorts users by name", function(){
10+
let nameSortedKey = [
11+
{ name: "Ann", age: 19, surname: "Hathaway" },
12+
{ name: "John", age: 20, surname: "Johnson"},
13+
{ name: "Pete", age: 18, surname: "Peterson" },
14+
];
15+
let nameSortedAnswer = users.sort(byField("name"));
16+
assert.deepEqual(nameSortedKey, nameSortedAnswer);
17+
});
18+
19+
it("sorts users by age", function(){
20+
let ageSortedKey = [
21+
{ name: "Pete", age: 18, surname: "Peterson" },
22+
{ name: "Ann", age: 19, surname: "Hathaway" },
23+
{ name: "John", age: 20, surname: "Johnson"},
24+
];
25+
let ageSortedAnswer = users.sort(byField("age"));
26+
assert.deepEqual(ageSortedKey, ageSortedKey);
27+
});
28+
29+
it("sorts users by surname", function(){
30+
let surnameSortedKey = [
31+
{ name: "Ann", age: 19, surname: "Hathaway" },
32+
{ name: "John", age: 20, surname: "Johnson"},
33+
{ name: "Pete", age: 18, surname: "Peterson" },
34+
];
35+
let surnameSortedAnswer = users.sort(byField("surname"));
36+
assert.deepEqual(surnameSortedAnswer, surnameSortedKey);
37+
});
38+
39+
});
Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1 @@
11

2-
3-
```js run
4-
let users = [
5-
{ name: "John", age: 20, surname: "Johnson" },
6-
{ name: "Pete", age: 18, surname: "Peterson" },
7-
{ name: "Ann", age: 19, surname: "Hathaway" }
8-
];
9-
10-
*!*
11-
function byField(field) {
12-
return (a, b) => a[field] > b[field] ? 1 : -1;
13-
}
14-
*/!*
15-
16-
users.sort(byField('name'));
17-
users.forEach(user => alert(user.name)); // Ann, John, Pete
18-
19-
users.sort(byField('age'));
20-
users.forEach(user => alert(user.name)); // Pete, Ann, John
21-
```
22-

1-js/08-prototypes/04-prototype-methods/article.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ The descriptors are in the same format as described in the chapter <info:propert
5757
We can use `Object.create` to perform an object cloning more powerful than copying properties in `for..in`:
5858

5959
```js
60-
// fully identical shallow clone of obj
6160
let clone = Object.create(Object.getPrototypeOf(obj), Object.getOwnPropertyDescriptors(obj));
6261
```
6362

2-ui/3-event-details/6-pointer-events/article.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Let's make a small overview, so that you understand the general picture and the
1010

1111
Then touch devices appeared. For the old code to work, they also generate mouse events. For instance, tapping generates `mousedown`. But mouse events were not good enough, as touch devices are more powerful in many aspects. For example, it's possible to touch multiple points at once, and mouse events don't have any properties for that.
1212

13-
- So touch events were introduced, such as `touchstart`, `touchend`, `touchmove`, that have touch-specific properties (we don't cover them in details here, because pointer events are event better).
13+
- So touch events were introduced, such as `touchstart`, `touchend`, `touchmove`, that have touch-specific properties (we don't cover them in detail here, because pointer events are even better).
1414

1515
Still, it wasn't enough, as there are many other devices, such as pens, that have their own features. Also, writing a code that listens both touch and mouse events was cumbersome.
1616

0 commit comments

Comments
 (0)