Skip to content

Commit 93eb07e

Browse files
author
root
committed
merging all conflicts
2 parents 057dd2d + 0279335 commit 93eb07e

File tree

51 files changed

+1909
-286
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+1909
-286
lines changed

1-js/01-getting-started/2-code-editors/article.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ Un IDE încarcă proiectul (pot fi mai multe fișiere), permite navigarea între
1212

1313
Dacă nu ai selectat până acum un IDE, uită-te la următoarele variante:
1414

15+
<<<<<<< HEAD
1516
- [WebStorm](http://www.jetbrains.com/webstorm/) pentru dezvoltare frontend și alte editoare ale aceleiași companii dacă ai nevoide de limbaje adiționale (plătit).
1617
- [Netbeans](http://netbeans.org/) (plătit).
1718

@@ -20,6 +21,14 @@ Toate IDE-urile sunt cross-platform.
2021
Pentru Windows există de asemenea un editor "Visual Studio", a nu se confunda cu "Visual Studio Code". "Visual Studio" este un editor doar pentru Windows, plătit dar puternic, foarte potrivit pentru platforma .NET. O versiune gratuită al lui este [Visual Studio Community](https://www.visualstudio.com/vs/community/).
2122

2223
Multe IDE-uri sunt plătite dar au o perioadă de încercare. Costul lor este în mod normal neglijabil, în comparație cu salariul unui dezvoltator calificat, așa că doar alege unul potrivit pentru tine.
24+
=======
25+
- [Visual Studio Code](https://code.visualstudio.com/) (cross-platform, free).
26+
- [WebStorm](http://www.jetbrains.com/webstorm/) (cross-platform, paid).
27+
28+
For Windows, there's also "Visual Studio", not to be confused with "Visual Studio Code". "Visual Studio" is a paid and mighty Windows-only editor, well-suited for the .NET platform. It's also good at JavaScript. There's also a free version [Visual Studio Community](https://www.visualstudio.com/vs/community/).
29+
30+
Many IDEs are paid, but have a trial period. Their cost is usually negligible compared to a qualified developer's salary, so just choose the best one for you.
31+
>>>>>>> 027933531e121650120f7e8385f691de99af12d2
2332
2433
## Editoare de categorie ușoară
2534

@@ -33,12 +42,17 @@ Diferența majoră dintre un editor de "categorie ușoară" și un "IDE" este c
3342

3443
Următoarele opțiuni merită atenția ta:
3544

45+
<<<<<<< HEAD
3646
- [Visual Studio Code](https://code.visualstudio.com/) (cross-platform, gratuit) de asemenea are multe feature-uri de tip IDE.
3747
- [Atom](https://atom.io/) (cross-platform, gratuit).
48+
=======
49+
- [Atom](https://atom.io/) (cross-platform, free).
50+
>>>>>>> 027933531e121650120f7e8385f691de99af12d2
3851
- [Sublime Text](http://www.sublimetext.com) (cross-platform, shareware).
3952
- [Notepad++](https://notepad-plus-plus.org/) (Windows, gratuit).
4053
- [Vim](http://www.vim.org/) și [Emacs](https://www.gnu.org/software/emacs/) sunt de asemenea utile dacă știi cum să le folosești.
4154

55+
<<<<<<< HEAD
4256
## Favoritele mele
4357

4458
Preferința personală a autorului este de a avea atât un IDE pentru proiecte cât și un editor de categorie ușoară pentru editare de fișiere rapidă și ușoară.
@@ -49,6 +63,9 @@ Eu folosesc:
4963
- Pe post de editor de categorie ușoară -- [Sublime Text](http://www.sublimetext.com) sau [Atom](https://atom.io/).
5064

5165
## Să nu ne certăm
66+
=======
67+
## Let's not argue
68+
>>>>>>> 027933531e121650120f7e8385f691de99af12d2
5269
5370
Editoarele din lista de mai sus sunt cele pe care fie eu sau prietenii mei, pe care îi consider dezvoltatori buni, le-am folosit pentru un timp îndelungat și suntem mulțumiți de ele.
5471

1-js/04-object-basics/03-symbol/article.md

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ A value of this type can be created using `Symbol()`:
1616
let id = Symbol();
1717
```
1818

19-
We can also give symbol a description (also called a symbol name), mostly useful for debugging purposes:
19+
Upon creation, we can give symbol a description (also called a symbol name), mostly useful for debugging purposes:
2020

2121
```js run
2222
// id is a symbol with the description "id"
@@ -74,7 +74,7 @@ alert(id.description); // id
7474

7575
Symbols allow us to create "hidden" properties of an object, that no other part of code can occasionally access or overwrite.
7676

77-
For instance, if we want to store an "identifier" for the object `user`, we can use a symbol as a key for it:
77+
For instance, if we'd like to add an "identifier" to the object `user`, we can use a symbol as a key for it:
7878

7979
```js run
8080
let user = { name: "John" };
@@ -88,7 +88,7 @@ What's the benefit of using `Symbol("id")` over a string `"id"`?
8888

8989
Let's make the example a bit deeper to see that.
9090

91-
Imagine that another script wants to have its own "id" property inside `user`, for its own purposes. That may be another JavaScript library, so the scripts are completely unaware of each other.
91+
Imagine that another script wants to have its own identifier inside `user`, for its own purposes. That may be another JavaScript library, so thes scripts are completely unaware of each other.
9292

9393
Then that script can create its own `Symbol("id")`, like this:
9494

@@ -99,9 +99,9 @@ let id = Symbol("id");
9999
user[id] = "Their id value";
100100
```
101101

102-
There will be no conflict, because symbols are always different, even if they have the same name.
102+
There will be no conflict between our and their identifiers, because symbols are always different, even if they have the same name.
103103

104-
Now note that if we used a string `"id"` instead of a symbol for the same purpose, then there *would* be a conflict:
104+
...But if we used a string `"id"` instead of a symbol for the same purpose, then there *would* be a conflict:
105105

106106
```js run
107107
let user = { name: "John" };
@@ -117,7 +117,7 @@ user.id = "Their id value"
117117

118118
### Symbols in a literal
119119

120-
If we want to use a symbol in an object literal, we need square brackets.
120+
If we want to use a symbol in an object literal `{...}`, we need square brackets around it.
121121

122122
Like this:
123123

@@ -155,7 +155,7 @@ for (let key in user) alert(key); // name, age (no symbols)
155155
alert( "Direct: " + user[id] );
156156
```
157157

158-
That's a part of the general "hiding" concept. If another script or a library loops over our object, it won't unexpectedly access a symbolic property.
158+
`Object.keys(user)` also ignores them. That's a part of the general "hiding symbolic properties" principle. If another script or a library loops over our object, it won't unexpectedly access a symbolic property.
159159

160160
In contrast, [Object.assign](mdn:js/Object/assign) copies both string and symbol properties:
161161

@@ -190,13 +190,13 @@ alert( obj[0] ); // test (same property)
190190

191191
## Global symbols
192192

193-
As we've seen, usually all symbols are different, even if they have the same names. But sometimes we want same-named symbols to be same entities.
193+
As we've seen, usually all symbols are different, even if they have the same name. But sometimes we want same-named symbols to be same entities.
194194

195195
For instance, different parts of our application want to access symbol `"id"` meaning exactly the same property.
196196

197197
To achieve that, there exists a *global symbol registry*. We can create symbols in it and access them later, and it guarantees that repeated accesses by the same name return exactly the same symbol.
198198

199-
In order to create or read a symbol in the registry, use `Symbol.for(key)`.
199+
In order to read (create if absent) a symbol from the registry, use `Symbol.for(key)`.
200200

201201
That call checks the global registry, and if there's a symbol described as `key`, then returns it, otherwise creates a new symbol `Symbol(key)` and stores it in the registry by the given `key`.
202202

@@ -206,7 +206,7 @@ For instance:
206206
// read from the global registry
207207
let id = Symbol.for("id"); // if the symbol did not exist, it is created
208208

209-
// read it again
209+
// read it again (maybe from another part of the code)
210210
let idAgain = Symbol.for("id");
211211

212212
// the same symbol
@@ -266,14 +266,14 @@ Other symbols will also become familiar when we study the corresponding language
266266

267267
`Symbol` is a primitive type for unique identifiers.
268268

269-
Symbols are created with `Symbol()` call with an optional description.
269+
Symbols are created with `Symbol()` call with an optional description (name).
270270

271-
Symbols are always different values, even if they have the same name. If we want same-named symbols to be equal, then we should use the global registry: `Symbol.for(key)` returns (creates if needed) a global symbol with `key` as the name. Multiple calls of `Symbol.for` return exactly the same symbol.
271+
Symbols are always different values, even if they have the same name. If we want same-named symbols to be equal, then we should use the global registry: `Symbol.for(key)` returns (creates if needed) a global symbol with `key` as the name. Multiple calls of `Symbol.for` with the same `key` return exactly the same symbol.
272272

273273
Symbols have two main use cases:
274274

275275
1. "Hidden" object properties.
276-
If we want to add a property into an object that "belongs" to another script or a library, we can create a symbol and use it as a property key. A symbolic property does not appear in `for..in`, so it won't be occasionally listed. Also it won't be accessed directly, because another script does not have our symbol, so it will not occasionally intervene into its actions.
276+
If we want to add a property into an object that "belongs" to another script or a library, we can create a symbol and use it as a property key. A symbolic property does not appear in `for..in`, so it won't be occasionally processed together with other properties. Also it won't be accessed directly, because another script does not have our symbol. So the property will be protected from occasional use or overwrite.
277277

278278
So we can "covertly" hide something into objects that we need, but others should not see, using symbolic properties.
279279

1-js/05-data-types/03-string/2-check-spam/task.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ importance: 5
44

55
# Check for spam
66

7-
Write a function `checkSpam(str)` that returns `true` if `str` contains 'viagra' or 'XXX', otherwise false.
7+
Write a function `checkSpam(str)` that returns `true` if `str` contains 'viagra' or 'XXX', otherwise `false`.
88

99
The function must be case-insensitive:
1010

1-js/05-data-types/04-array/2-create-array/task.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ The array in the process:
1616

1717
```js no-beautify
1818
Jazz, Blues
19-
Jazz, Bues, Rock-n-Roll
19+
Jazz, Blues, Rock-n-Roll
2020
Jazz, Classics, Rock-n-Roll
2121
Classics, Rock-n-Roll
2222
Rap, Reggae, Classics, Rock-n-Roll

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -453,7 +453,7 @@ We can use an array as a deque with the following operations:
453453
- `push(...items)` adds `items` to the end.
454454
- `pop()` removes the element from the end and returns it.
455455
- `shift()` removes the element from the beginning and returns it.
456-
- `unshift(...items)` adds items to the beginning.
456+
- `unshift(...items)` adds `items` to the beginning.
457457

458458
To loop over the elements of the array:
459459
- `for (let i=0; i<arr.length; i++)` -- works fastest, old-browser-compatible.

1-js/05-data-types/07-map-set-weakmap-weakset/article.md

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,24 @@ alert( visitsCountMap.get(john) ); // 123
5858

5959
Using objects as keys is one of most notable and important `Map` features. For string keys, `Object` can be fine, but it would be difficult to replace the `Map` with a regular `Object` in the example above.
6060

61-
In the old times, before `Map` existed, people added unique identifiers to objects for that:
61+
Let's try:
62+
63+
```js run
64+
let john = { name: "John" };
65+
66+
let visitsCountObj = {}; // try to use an object
67+
68+
visitsCountObj[john] = 123; // try to use john object as the key
69+
70+
*!*
71+
// That's what got written!
72+
alert( visitsCountObj["[object Object]"] ); // 123
73+
*/!*
74+
```
75+
76+
As `john` is an object, it got converted to the key string `"[object Object]"`. All objects without a special conversion handling are converted to such string, so they'll all mess up.
77+
78+
In the old times, before `Map` existed, people used to add unique identifiers to objects for that:
6279

6380
```js run
6481
// we add the id field
@@ -159,7 +176,7 @@ The iteration goes in the same order as the values were inserted. `Map` preserve
159176
Besides that, `Map` has a built-in `forEach` method, similar to `Array`:
160177
161178
```js
162-
// runs the function for each (key, value) pair
179+
// runs the function for each (key, value) pair
163180
recipeMap.forEach( (value, key, map) => {
164181
alert(`${key}: ${value}`); // cucumber: 500 etc
165182
});
@@ -172,7 +189,7 @@ A `Set` is a collection of values, where each value may occur only once.
172189
173190
Its main methods are:
174191
175-
- `new Set(iterable)` -- creates the set, optionally from an array of values (any iterable will do).
192+
- `new Set(iterable)` -- creates the set, and if an `iterable` object is provided (usually an array), copies values from it into the set.
176193
- `set.add(value)` -- adds a value, returns the set itself.
177194
- `set.delete(value)` -- removes the value, returns `true` if `value` existed at the moment of the call, otherwise `false`.
178195
- `set.has(value)` -- returns `true` if the value exists in the set, otherwise `false`.
@@ -222,9 +239,9 @@ set.forEach((value, valueAgain, set) => {
222239
});
223240
```
224241
225-
Note the funny thing. The `forEach` function in the `Set` has 3 arguments: a value, then *again a value*, and then the target object. Indeed, the same value appears in the arguments twice.
242+
Note the funny thing. The callback function passed in `forEach` has 3 arguments: a value, then *again a value*, and then the target object. Indeed, the same value appears in the arguments twice.
226243
227-
That's for compatibility with `Map` where `forEach` has three arguments. Looks a bit strange, for sure. But may help to replace `Map` with `Set` in certain cases with ease, and vice versa.
244+
That's for compatibility with `Map` where the callback passed `forEach` has three arguments. Looks a bit strange, for sure. But may help to replace `Map` with `Set` in certain cases with ease, and vice versa.
228245
229246
The same methods `Map` has for iterators are also supported:
230247

1-js/05-data-types/08-keys-values-entries/article.md

Lines changed: 90 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11

22
# Object.keys, values, entries
33

4-
Let's step away from the individual data structures and talk about the iterations over them.
4+
Let's step away from the individual data structures and talk about the iterations over them.
55

66
In the previous chapter we saw methods `map.keys()`, `map.values()`, `map.entries()`.
77

8-
These methods are generic, there is a common agreement to use them for data structures. If we ever create a data structure of our own, we should implement them too.
8+
These methods are generic, there is a common agreement to use them for data structures. If we ever create a data structure of our own, we should implement them too.
99

1010
They are supported for:
1111

@@ -63,8 +63,93 @@ for (let value of Object.values(user)) {
6363
}
6464
```
6565

66-
## Object.keys/values/entries ignore symbolic properties
67-
66+
```warn header="Object.keys/values/entries ignore symbolic properties"
6867
Just like a `for..in` loop, these methods ignore properties that use `Symbol(...)` as keys.
6968
70-
Usually that's convenient. But if we want symbolic keys too, then there's a separate method [Object.getOwnPropertySymbols](mdn:js/Object/getOwnPropertySymbols) that returns an array of only symbolic keys. Also, the method [Reflect.ownKeys(obj)](mdn:js/Reflect/ownKeys) returns *all* keys.
69+
Usually that's convenient. But if we want symbolic keys too, then there's a separate method [Object.getOwnPropertySymbols](mdn:js/Object/getOwnPropertySymbols) that returns an array of only symbolic keys. Also, there exist a method [Reflect.ownKeys(obj)](mdn:js/Reflect/ownKeys) that returns *all* keys.
70+
```
71+
72+
## Object.fromEntries to transform objects
73+
74+
Sometimes we need to perform a transformation of an object to `Map` and back.
75+
76+
We already have `new Map(Object.entries(obj))` to make a `Map` from `obj`.
77+
78+
The syntax of `Object.fromEntries` does the reverse. Given an array of `[key, value]` pairs, it creates an object:
79+
80+
```js run
81+
let prices = Object.fromEntries([
82+
['banana', 1],
83+
['orange', 2],
84+
['meat', 4]
85+
]);
86+
87+
// now prices = { banana: 1, orange: 2, meat: 4 }
88+
89+
alert(prices.orange); // 2
90+
```
91+
92+
Let's see practical applications.
93+
94+
For example, we'd like to create a new object with double prices from the existing one.
95+
96+
For arrays, we have `.map` method that allows to transform an array, but nothing like that for objects.
97+
98+
So we can use a loop:
99+
100+
```js run
101+
let prices = {
102+
banana: 1,
103+
orange: 2,
104+
meat: 4,
105+
};
106+
107+
let doublePrices = {};
108+
for(let [product, price] of Object.entries(prices)) {
109+
doublePrices[product] = price * 2;
110+
}
111+
112+
alert(doublePrices.meat); // 8
113+
```
114+
115+
...Or we can represent the object as an `Array` using `Object.entries`, then perform the operations with `map` (and potentially other array methods), and then go back using `Object.fromEntries`.
116+
117+
Let's do it for our object:
118+
119+
```js run
120+
let prices = {
121+
banana: 1,
122+
orange: 2,
123+
meat: 4,
124+
};
125+
126+
*!*
127+
let doublePrices = Object.fromEntries(
128+
// convert to array, map, and then fromEntries gives back the object
129+
Object.entries(prices).map(([key, value]) => [key, value * 2])
130+
);
131+
*/!*
132+
133+
alert(doublePrices.meat); // 8
134+
```
135+
136+
It may look difficult from the first sight, but becomes easy to understand after you use it once or twice.
137+
138+
We also can use `fromEntries` to get an object from `Map`.
139+
140+
E.g. we have a `Map` of prices, but we need to pass it to a 3rd-party code that expects an object.
141+
142+
Here we go:
143+
144+
```js run
145+
let map = new Map();
146+
map.set('banana', 1);
147+
map.set('orange', 2);
148+
map.set('meat', 4);
149+
150+
let obj = Object.fromEntries(map);
151+
152+
// now obj = { banana: 1, orange: 2, meat: 4 }
153+
154+
alert(obj.orange); // 2
155+
```

1-js/06-advanced-functions/01-recursion/01-sum-to/solution.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,4 @@ P.S. Naturally, the formula is the fastest solution. It uses only 3 operations f
3737

3838
The loop variant is the second in terms of speed. In both the recursive and the loop variant we sum the same numbers. But the recursion involves nested calls and execution stack management. That also takes resources, so it's slower.
3939

40-
P.P.S. The standard describes a "tail call" optimization: if the recursive call is the very last one in the function (like in `sumTo` above), then the outer function will not need to resume the execution and we don't need to remember its execution context. In that case `sumTo(100000)` is countable. But if your JavaScript engine does not support it, there will be an error: maximum stack size exceeded, because there's usually a limitation on the total stack size.
40+
P.P.S. Some engines support the "tail call" optimization: if a recursive call is the very last one in the function (like in `sumTo` above), then the outer function will not need to resume the execution, so the engine doesn't need to remember its execution context. That removes the burden on memory, so counting `sumTo(100000)` becomes possible. But if the JavaScript engine does not support tail call optimization (most of them don't), there will be an error: maximum stack size exceeded, because there's usually a limitation on the total stack size.

1-js/06-advanced-functions/01-recursion/05-output-single-linked-list-reverse/solution.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ The loop variant is also a little bit more complicated then the direct output.
3737

3838
There is no way to get the last value in our `list`. We also can't "go back".
3939

40-
So what we can do is to first go through the items in the direct order and rememeber them in an array, and then output what we remembered in the reverse order:
40+
So what we can do is to first go through the items in the direct order and remember them in an array, and then output what we remembered in the reverse order:
4141

4242
```js run
4343
let list = {

0 commit comments

Comments
 (0)