Skip to content

Commit 8416388

Browse files
authored
Small grammatical changes
Small changes to improve readability.
1 parent 4b02949 commit 8416388

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
@@ -1,16 +1,16 @@
11

22
# Map, Set, WeakMap and WeakSet
33

4-
Now we know the following complex data structures:
4+
Now we've learned about the following complex data structures:
55

66
- Objects for storing keyed collections.
77
- Arrays for storing ordered collections.
88

9-
But that's not enough for real life. That's why there also exist `Map` and `Set`.
9+
But that's not enough for real life. That's why `Map` and `Set` also exist.
1010

1111
## Map
1212

13-
[Map](mdn:js/Map) is a collection of keyed data items. Just like an `Object`. But the main difference is that `Map` allows keys of any type.
13+
[Map](mdn:js/Map) is a collection of keyed data items, just like an `Object`. But the main difference is that `Map` allows keys of any type.
1414

1515
The main methods are:
1616

@@ -20,7 +20,7 @@ The main methods are:
2020
- `map.has(key)` -- returns `true` if the `key` exists, `false` otherwise.
2121
- `map.delete(key)` -- removes the value by the key.
2222
- `map.clear()` -- clears the map
23-
- `map.size` -- is the current elements count.
23+
- `map.size` -- returns the current element count.
2424

2525
For instance:
2626

@@ -76,7 +76,7 @@ alert( visitsCounts[john.id] ); // 123
7676

7777

7878
```smart header="How `Map` compares keys"
79-
To test values for equivalence, `Map` uses the algorithm [SameValueZero](https://tc39.github.io/ecma262/#sec-samevaluezero). It is roughly the same as the strict equality `===`, but the difference is that `NaN` is considered equal to `NaN`. So `NaN` can be used as the key as well.
79+
To test values for equivalence, `Map` uses the algorithm [SameValueZero](https://tc39.github.io/ecma262/#sec-samevaluezero). It is roughly the same as strict equality `===`, but the difference is that `NaN` is considered equal to `NaN`. So `NaN` can be used as the key as well.
8080

8181
This algorithm can't be changed or customized.
8282
```
@@ -106,7 +106,7 @@ let map = new Map([
106106
]);
107107
```
108108
109-
There is a built-in method [Object.entries(obj)](mdn:js/Object/entries) that returns the array of key/value pairs for an object exactly in that format.
109+
There is a built-in method [Object.entries(obj)](mdn:js/Object/entries) that returns an array of key/value pairs for an object exactly in that format.
110110
111111
So we can initialize a map from an object like this:
112112
@@ -167,9 +167,9 @@ recipeMap.forEach( (value, key, map) => {
167167
168168
## Set
169169
170-
`Set` -- is a collection of values, where each value may occur only once.
170+
A `Set` is a collection of values, where each value may occur only once.
171171
172-
The main methods are:
172+
Its main methods are:
173173
174174
- `new Set(iterable)` -- creates the set, optionally from an array of values (any iterable will do).
175175
- `set.add(value)` -- adds a value, returns the set itself.
@@ -223,9 +223,9 @@ set.forEach((value, valueAgain, set) => {
223223
224224
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.
225225
226-
That's made for compatibility with `Map` where `forEach` has three arguments.
226+
That's for compatibility with `Map` where `forEach` has three arguments.
227227
228-
The same methods as `Map` has for iterators are also supported:
228+
The same methods `Map` has for iterators are also supported:
229229
230230
- `set.keys()` -- returns an iterable object for values,
231231
- `set.values()` -- same as `set.keys`, for compatibility with `Map`,
@@ -330,9 +330,9 @@ weakMap.put(john, "secret documents");
330330
331331
That's useful for situations when we have a main storage for the objects somewhere and need to keep additional information that is only relevant while the object lives.
332332
333-
Let's see an example.
333+
Let's look at 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 anymore.
335+
For instance, we have 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

0 commit comments

Comments
 (0)