Skip to content

Commit 5d52b99

Browse files
authored
Merge pull request #109 from adriavieira314/master
Array methods
2 parents 9d3c4f5 + 219bee6 commit 5d52b99

File tree

24 files changed

+379
-380
lines changed

24 files changed

+379
-380
lines changed
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
function camelize(str) {
22
return str
3-
.split('-') // splits 'my-long-word' into array ['my', 'long', 'word']
3+
.split('-') // separa 'my-long-word' em um array ['my', 'long', 'word']
44
.map(
5-
// capitalizes first letters of all array items except the first one
6-
// converts ['my', 'long', 'word'] into ['my', 'Long', 'Word']
5+
// deixa as primeiras letras de todos os itens do array em maiúsculo exceto o primeiro item
6+
// converte ['my', 'long', 'word'] em ['my', 'Long', 'Word']
77
(word, index) => index == 0 ? word : word[0].toUpperCase() + word.slice(1)
88
)
9-
.join(''); // joins ['my', 'Long', 'Word'] into 'myLongWord'
9+
.join(''); // une ['my', 'Long', 'Word'] formando 'myLongWord'
1010
}

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,18 @@ importance: 5
22

33
---
44

5-
# Translate border-left-width to borderLeftWidth
5+
# Mude border-left-width para borderLeftWidth
66

7-
Write the function `camelize(str)` that changes dash-separated words like "my-short-string" into camel-cased "myShortString".
7+
Escreva uma função `camelize(str)` que mude as palavras separadas por traços como "my-short-string" para palavras em camelCase "myShortString".
88

9-
That is: removes all dashes, each word after dash becomes uppercased.
9+
Ou seja: remova todos os traços, cada palavra depois do traço precisa estar em maiúsculo.
1010

11-
Examples:
11+
Exemplos:
1212

1313
```js
1414
camelize("background-color") == 'backgroundColor';
1515
camelize("list-style-image") == 'listStyleImage';
1616
camelize("-webkit-transition") == 'WebkitTransition';
1717
```
1818

19-
P.S. Hint: use `split` to split the string into an array, transform it and `join` back.
19+
P.S. Dica: use `split` para separar a string em um array, transforme-os e os junte de volta usando `join`.

1-js/05-data-types/05-array-methods/10-average-age/task.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@ importance: 4
22

33
---
44

5-
# Get average age
5+
# Pegar a média de idade
66

7-
Write the function `getAverageAge(users)` that gets an array of objects with property `age` and returns the average age.
7+
Escreva a função `getAverageAge(users)` que recebe um array de objetos com a propriedade `age` e pega a média entre eles.
88

9-
The formula for the average is `(age1 + age2 + ... + ageN) / N`.
9+
A fórmula da média é `(age1 + age2 + ... + ageN) / N`.
1010

11-
For instance:
11+
Por exemplo:
1212

1313
```js no-beautify
1414
let john = { name: "John", age: 25 };

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> we'll see how to optimize it.
39+
Mais adiante no capítulo <info:map-set> vamos ver como otimizar isso.

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,17 @@ importance: 4
22

33
---
44

5-
# Filter unique array members
5+
# Filtre membros únicos de um array
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 deve retornar um array com itens únicos de `arr`.
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",
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

22
function filterRange(arr, a, b) {
3-
// added brackets around the expression for better readability
3+
// colchetes adicionado ao redor da expressão para melhor entendimento
44
return arr.filter(item => (a <= item && item <= b));
55
}
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
```js run demo
22
function filterRange(arr, a, b) {
3-
// added brackets around the expression for better readability
3+
// colchetes adicionado ao redor da expressão para melhor entendimento
44
return arr.filter(item => (a <= item && item <= b));
55
}
66

77
let arr = [5, 3, 8, 1];
88

99
let filtered = filterRange(arr, 1, 4);
1010

11-
alert( filtered ); // 3,1 (matching values)
11+
alert( filtered ); // 3,1 (valores que coincidem com o que foi pedido)
1212

13-
alert( arr ); // 5,3,8,1 (not modified)
13+
alert( arr ); // 5,3,8,1 (array não foi modificada)
1414
```

1-js/05-data-types/05-array-methods/2-filter-range/task.md

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

55
# Filter range
66

7-
Write a function `filterRange(arr, a, b)` that gets an array `arr`, looks for elements with values higher or equal to `a` and lower or equal to `b` and return a result as an array.
7+
Escreva uma função `filterRange(arr, a, b)` que pegue um array `arr`, procure por elementos entre `a` e `b` e retorne um array novo com os elementos encontrados.
88

9-
The function should not modify the array. It should return the new array.
9+
A função não deve modificar o array. Deve retornar um novo array.
1010

11-
For instance:
11+
Exemplo:
1212

1313
```js
1414
let arr = [5, 3, 8, 1];
1515

1616
let filtered = filterRange(arr, 1, 4);
1717

18-
alert( filtered ); // 3,1 (matching values)
18+
alert( filtered ); // 3,1 (valores que coincidem com o que foi pedido)
1919

20-
alert( arr ); // 5,3,8,1 (not modified)
20+
alert( arr ); // 5,3,8,1 (array não foi modificada)
2121
```
2222

1-js/05-data-types/05-array-methods/3-filter-range-in-place/_js.view/solution.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ function filterRangeInPlace(arr, a, b) {
44
for (let i = 0; i < arr.length; i++) {
55
let val = arr[i];
66

7-
// remove if outside of the interval
7+
//remove se estiver fora do intervalo
88
if (val < a || val > b) {
99
arr.splice(i, 1);
1010
i--;

1-js/05-data-types/05-array-methods/3-filter-range-in-place/solution.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ function filterRangeInPlace(arr, a, b) {
44
for (let i = 0; i < arr.length; i++) {
55
let val = arr[i];
66

7-
// remove if outside of the interval
7+
//remove se estiver fora do intervalo
88
if (val < a || val > b) {
99
arr.splice(i, 1);
1010
i--;
@@ -15,7 +15,7 @@ function filterRangeInPlace(arr, a, b) {
1515

1616
let arr = [5, 3, 8, 1];
1717

18-
filterRangeInPlace(arr, 1, 4); // removed the numbers except from 1 to 4
18+
filterRangeInPlace(arr, 1, 4); // remove os números exceto números de 1 á 4
1919

2020
alert( arr ); // [3, 1]
2121
```

0 commit comments

Comments
 (0)