Skip to content

Commit be3a6e4

Browse files
author
Adria Vieira
committed
array-unique task translated
1 parent 04c309e commit be3a6e4

File tree

2 files changed

+15
-15
lines changed

2 files changed

+15
-15
lines changed

1-js/05-data-types/05-array-methods/11-array-unique/solution.md

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
Let's walk the array items:
2-
- For each item we'll check if the resulting array already has that item.
3-
- If it is so, then ignore, otherwise add to results.
1+
Vamos percorrer os itens do array:
2+
- Para cada item, vamos checar se o array `result` já possui esse item.
3+
- Se sim, então será ignorado, do contrário será adicionado a `result`.
44

55
```js run demo
66
function unique(arr) {
@@ -22,18 +22,18 @@ let strings = ["Hare", "Krishna", "Hare", "Krishna",
2222
alert( unique(strings) ); // Hare, Krishna, :-O
2323
```
2424

25-
The code works, but there's a potential performance problem in it.
25+
O código funciona, porém existe um potencial problema de performance aqui.
2626

27-
The method `result.includes(str)` internally walks the array `result` and compares each element against `str` to find the match.
27+
O método `result.includes(str)` internamente percorre o array `result` e compara cada elemento com `str` para achar um que combine.
2828

29-
So if there are `100` elements in `result` and no one matches `str`, then it will walk the whole `result` and do exactly `100` comparisons. And if `result` is large, like `10000`, then there would be `10000` comparisons.
29+
Então se tiver `100` elementos em `result` e nenhum combine com `str`, então ele vai percorrer `result` inteiro e fazer exatamente `100` comparações. E se `result` for muito maior, como `10000`, então terá `10000` comparações.
3030

31-
That's not a problem by itself, because JavaScript engines are very fast, so walk `10000` array is a matter of microseconds.
31+
Isso não é um problema tão preocupante porque as engines do JavaScript são muito rápidas, então percorrer um array de `10000` itens dura questões de microsegundos.
3232

33-
But we do such test for each element of `arr`, in the `for` loop.
33+
Porém, nós estamos fazendo estes teste para cada elemento em `arr` no laço de repetição `for`.
3434

35-
So if `arr.length` is `10000` we'll have something like `10000*10000` = 100 millions of comparisons. That's a lot.
35+
Então se `arr.length` for `10000` vamos ter algo como: `10000*10000` = 100 milhões de comparações. Isso é muito.
3636

37-
So the solution is only good for small arrays.
37+
Então, essa solução é somente boa para arrays pequenas.
3838

39-
Further in the chapter <info:map-set-weakmap-weakset> we'll see how to optimize it.
39+
Mais adiante no capítulo <info:map-set-weakmap-weakset> vamos ver como otimizar isso.

1-js/05-data-types/05-array-methods/11-array-unique/task.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@ importance: 4
44

55
# Filter unique array members
66

7-
Let `arr` be an array.
7+
Deixe `arr` ser um array.
88

9-
Create a function `unique(arr)` that should return an array with unique items of `arr`.
9+
Crie a função `unique(arr)` que recebe um array `string` e retorna outro array `arr` com itens únicos/que mais se repetem do array recebido.
1010

11-
For instance:
11+
Por exemplo:
1212

1313
```js
1414
function unique(arr) {
15-
/* your code */
15+
/* seu código */
1616
}
1717

1818
let strings = ["Hare", "Krishna", "Hare", "Krishna",

0 commit comments

Comments
 (0)