Skip to content

Commit 9e0410b

Browse files
committed
translate section map
1 parent 65377ed commit 9e0410b

File tree

1 file changed

+35
-35
lines changed

1 file changed

+35
-35
lines changed

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

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -10,88 +10,88 @@ Mas isso não é suficiente para a vida real. É por isso que `Map` e `Set` tamb
1010

1111
## Map
1212

13-
[Map](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/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](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map) é uma coleção de itens de dados indexados, assim como um `Object`. Mas a principal diferença é que `Map` permite chaves de qualquer tipo.
1414

15-
Methods and properties are:
15+
Métodos e propriedades são:
1616

17-
- [`new Map()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/Map) -- creates the map.
18-
- [`map.set(key, value)`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/set) -- stores the value by the key.
19-
- [`map.get(key)`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/get) -- returns the value by the key, `undefined` if `key` doesn't exist in map.
20-
- [`map.has(key)`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/has) -- returns `true` if the `key` exists, `false` otherwise.
21-
- [`map.delete(key)`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/delete) -- removes the element (the key/value pair) by the key.
22-
- [`map.clear()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/clear) -- removes everything from the map.
23-
- [`map.size`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/size) -- returns the current element count.
17+
- [`new Map()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/Map) -- cria o mapa.
18+
- [`map.set(chave, valor)`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/set) -- armazena o valor pela chave.
19+
- [`map.get(chave)`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/get) -- retorna o valor pela chave, `undefined` se a `chave` não existir no mapa.
20+
- [`map.has(chave)`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/has) -- retorna `true` se a `chave` existir, `false` caso contrário.
21+
- [`map.delete(chave)`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/delete) -- remove o elemento (o par chave/valor) pela chave.
22+
- [`map.clear()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/clear) -- remove tudo do mapa.
23+
- [`map.size`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/size) -- retorna a contagem atual de elementos.
2424

25-
For instance:
25+
Por exemplo:
2626

2727
```js run
2828
let map = new Map();
2929

30-
map.set('1', 'str1'); // a string key
31-
map.set(1, 'num1'); // a numeric key
32-
map.set(true, 'bool1'); // a boolean key
30+
map.set('1', 'str1'); // uma chave de string
31+
map.set(1, 'num1'); // uma chave numérica
32+
map.set(true, 'bool1'); // uma chave booleana
3333

34-
// remember the regular Object? it would convert keys to string
35-
// Map keeps the type, so these two are different:
34+
// lembra do objeto normal? Ele converteria as chaves para string
35+
// Map mantém o tipo, então esses dois são diferentes:
3636
alert( map.get(1) ); // 'num1'
3737
alert( map.get('1') ); // 'str1'
3838

3939
alert( map.size ); // 3
4040
```
4141

42-
As we can see, unlike objects, keys are not converted to strings. Any type of key is possible.
42+
Como podemos ver, ao contrário de objetos, as chaves não são convertidas em strings. Qualquer tipo de chave é possível.
4343

44-
```smart header="`map[key]` isn't the right way to use a `Map`"
45-
Although `map[key]` also works, e.g. we can set `map[key] = 2`, this is treating `map` as a plain JavaScript object, so it implies all corresponding limitations (only string/symbol keys and so on).
44+
```smart header="`map[chave]` não é a maneira correta de usar um `Map`"
45+
Embora `map[chave]` também funcione, por exemplo, podemos definir `map[chave] = 2`, isso trata o `map` como um objeto JavaScript simples, o que implica todas as limitações correspondentes (apenas chaves de string/símbolo, entre outras).
4646

47-
So we should use `map` methods: `set`, `get` and so on.
47+
Portanto, devemos usar os métodos do `map`: `set`, `get` e assim por diante.
4848
```
4949
50-
**Map can also use objects as keys.**
50+
**Map também pode usar objetos como chaves.**
5151
52-
For instance:
52+
Por exemplo:
5353
5454
```js run
5555
let john = { name: "John" };
5656
57-
// for every user, let's store their visits count
57+
// para cada usuário, vamos armazenar a contagem de suas visitas.
5858
let visitsCountMap = new Map();
5959
60-
// john is the key for the map
60+
// john é a chave para o mapa
6161
visitsCountMap.set(john, 123);
6262
6363
alert( visitsCountMap.get(john) ); // 123
6464
```
6565

66-
Using objects as keys is one of the most notable and important `Map` features. The same does not count for `Object`. String as a key in `Object` is fine, but we can't use another `Object` as a key in `Object`.
66+
Usar objetos como chaves é uma das características mais notáveis e importantes do `Map`. O mesmo não se aplica ao `Object`. Usar uma string como chave em um `Object` é aceitável, mas não podemos usar outro `Object` como chave em um `Object`.
6767

68-
Let's try:
68+
Vamos tentar:
6969

7070
```js run
7171
let john = { name: "John" };
7272
let ben = { name: "Ben" };
7373

74-
let visitsCountObj = {}; // try to use an object
74+
let visitsCountObj = {}; // tente usar um objeto
7575

76-
visitsCountObj[ben] = 234; // try to use ben object as the key
77-
visitsCountObj[john] = 123; // try to use john object as the key, ben object will get replaced
76+
visitsCountObj[ben] = 234; // tente usar o objeto ben como chave
77+
visitsCountObj[john] = 123; // tente usar o objeto john como chave, o objeto ben será substituído
7878

7979
*!*
80-
// That's what got written!
80+
// Isso é o que foi escrito!
8181
alert( visitsCountObj["[object Object]"] ); // 123
8282
*/!*
8383
```
8484

85-
As `visitsCountObj` is an object, it converts all `Object` keys, such as `john` and `ben` above, to same string `"[object Object]"`. Definitely not what we want.
85+
"Como `visitsCountObj` é um objeto, ele converte todas as chaves de `Object`, como `john` e `ben` acima, para a mesma string `"[object Object]"`. Definitivamente, não é o que queremos."
8686

87-
```smart header="How `Map` compares keys"
88-
To test keys 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.
87+
```smart header="Como o `Map` compara chaves"
88+
Para testar as chaves quanto à equivalência, o `Map` utiliza o algoritmo [SameValueZero](https://tc39.github.io/ecma262/#sec-samevaluezero). Ele é essencialmente o mesmo que a igualdade estrita `===`, mas a diferença é que `NaN` é considerado igual a `NaN`. Portanto, `NaN` pode ser usado como chave também.
8989

90-
This algorithm can't be changed or customized.
90+
Este algoritmo não pode ser alterado ou personalizado.
9191
```
9292
93-
````smart header="Chaining"
94-
Every `map.set` call returns the map itself, so we can "chain" the calls:
93+
````smart header="Encadeamento"
94+
Cada chamada de `map.set` retorna o próprio mapa, então podemos "encadear" as chamadas:
9595
9696
```js
9797
map.set('1', 'str1')

0 commit comments

Comments
 (0)