Skip to content

Commit 3d9ac01

Browse files
authored
Merge pull request #86 from javascript-tutorial/sync-b52aa942
Sync with upstream @ b52aa94
2 parents fed6de2 + bda0103 commit 3d9ac01

9 files changed

Lines changed: 53 additions & 30 deletions

File tree

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/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: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,7 @@ alert(rabbit.jumps); // true
5858

5959
```js
6060
// كائن جديد مماثل تمامًا
61-
let clone = Object.create(
62-
Object.getPrototypeOf(obj),
63-
Object.getOwnPropertyDescriptors(obj)
64-
);
61+
let clone = Object.create(Object.getPrototypeOf(obj), Object.getOwnPropertyDescriptors(obj));
6562
```
6663

6764
هذا الإستدعاء يقوم بإنشاء نسخه طبق الأصل من الكائن `obj` بما فيه من خصائص سواءًا كانت معدودة (enumerable) أم لا وكذلك الجالبات والمغيرات (getters & setters) -- كل شيئ وبالخاصية `[[Prototype]]` الصحيحة.

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

5-network/11-websocket/article.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ let socket = new WebSocket("*!*ws*/!*://javascript.info");
1515
There's also encrypted `wss://` protocol. It's like HTTPS for websockets.
1616

1717
```smart header="Always prefer `wss://`"
18-
The `wss://` protocol not only encrypted, but also more reliable.
18+
The `wss://` protocol is not only encrypted, but also more reliable.
1919

2020
That's because `ws://` data is not encrypted, visible for any intermediary. Old proxy servers do not know about WebSocket, they may see "strange" headers and abort the connection.
2121

0 commit comments

Comments
 (0)