Skip to content

Commit ff01c05

Browse files
authored
Merge pull request javascript-tutorial#266 from usernamehw/patch-13
Update article.md
2 parents 0f0a844 + c2eea5d commit ff01c05

File tree

1 file changed

+12
-12
lines changed
  • 1-js/05-data-types/07-map-set-weakmap-weakset

1 file changed

+12
-12
lines changed

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

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -137,17 +137,17 @@ let recipeMap = new Map([
137137
]);
138138
139139
// iterate over keys (vegetables)
140-
for(let vegetable of recipeMap.keys()) {
140+
for (let vegetable of recipeMap.keys()) {
141141
alert(vegetable); // cucumber, tomateos, onion
142142
}
143143
144144
// iterate over values (amounts)
145-
for(let amount of recipeMap.values()) {
145+
for (let amount of recipeMap.values()) {
146146
alert(amount); // 500, 350, 50
147147
}
148148
149149
// iterate over [key, value] entries
150-
for(let entry of recipeMap) { // the same as of recipeMap.entries()
150+
for (let entry of recipeMap) { // the same as of recipeMap.entries()
151151
alert(entry); // cucumber,500 (and so on)
152152
}
153153
```
@@ -199,7 +199,7 @@ set.add(mary);
199199
// set keeps only unique values
200200
alert( set.size ); // 3
201201
202-
for(let user of set) {
202+
for (let user of set) {
203203
alert(user.name); // John (then Pete and Mary)
204204
}
205205
```
@@ -213,7 +213,7 @@ We can loop over a set either with `for..of` or using `forEach`:
213213
```js run
214214
let set = new Set(["oranges", "apples", "bananas"]);
215215
216-
for(let value of set) alert(value);
216+
for (let value of set) alert(value);
217217
218218
// the same with forEach:
219219
set.forEach((value, valueAgain, set) => {
@@ -332,7 +332,7 @@ That's useful for situations when we have a main storage for the objects somewhe
332332
333333
Let's see an example.
334334
335-
For instance, we have a code that keeps a visit count for each user. The information is stored in a map: a user is the key and the visit count is the value. When a user leaves, we don't want to store his visit count any more.
335+
For instance, we have a code that keeps a visit count for each user. The information is stored in a map: a user is the key and the visit count is the value. When a user leaves, we don't want to store his visit count anymore.
336336
337337
One way would be to keep track of leaving users and clean up the storage manually:
338338
@@ -345,7 +345,7 @@ let visitsCountMap = new Map();
345345
// john is the key for the map
346346
visitsCountMap.set(john, 123);
347347
348-
// now john leaves us, we don't need him any more
348+
// now john leaves us, we don't need him anymore
349349
john = null;
350350
351351
*!*
@@ -364,7 +364,7 @@ let visitsCountMap = new WeakMap();
364364
365365
visitsCountMap.set(john, 123);
366366
367-
// now john leaves us, we don't need him any more
367+
// now john leaves us, we don't need him anymore
368368
john = null;
369369
370370
// there are no references except WeakMap,
@@ -408,7 +408,7 @@ The most notable limitation of `WeakMap` and `WeakSet` is the absence of iterati
408408
409409
## Summary
410410
411-
- `Map` -- is a a collection of keyed values.
411+
- `Map` -- is a collection of keyed values.
412412
413413
The differences from a regular `Object`:
414414
@@ -421,12 +421,12 @@ The most notable limitation of `WeakMap` and `WeakSet` is the absence of iterati
421421
- Unlike an array, does not allow to reorder elements.
422422
- Keeps the insertion order.
423423
424-
- `WeakMap` -- a variant of `Map` that allows only objects as keys and removes them once they become unaccessible by other means.
424+
- `WeakMap` -- a variant of `Map` that allows only objects as keys and removes them once they become inaccessible by other means.
425425
426426
- It does not support operations on the structure as a whole: no `size`, no `clear()`, no iterations.
427427
428-
- `WeakSet` -- is a variant of `Set` that only stores objects and removes them once they become unaccessible by other means.
428+
- `WeakSet` -- is a variant of `Set` that only stores objects and removes them once they become inaccessible by other means.
429429
430430
- Also does not support `size/clear()` and iterations.
431431
432-
`WeakMap` and `WeakSet` are used as "secondary" data structures in additional to the "main" object storage. Once the object is removed from the main storage, so it only stays in `WeakMap/WeakSet`, they clean up aumatically.
432+
`WeakMap` and `WeakSet` are used as "secondary" data structures in addition to the "main" object storage. Once the object is removed from the main storage, so it only stays in `WeakMap/WeakSet`, they clean up automatically.

0 commit comments

Comments
 (0)