diff --git a/1-js/05-data-types/04-array/1-item-value/solution.md b/1-js/05-data-types/04-array/1-item-value/solution.md
index e631f1c70..d9842e3c6 100644
--- a/1-js/05-data-types/04-array/1-item-value/solution.md
+++ b/1-js/05-data-types/04-array/1-item-value/solution.md
@@ -1,8 +1,8 @@
-The result is `4`:
+O resultado é `4`:
```js run
-let fruits = ["Apples", "Pear", "Orange"];
+let fruits = ["Maçã", "Pera", "Laranja"];
let shoppingCart = fruits;
@@ -13,5 +13,5 @@ alert( fruits.length ); // 4
*/!*
```
-That's because arrays are objects. So both `shoppingCart` and `fruits` are the references to the same array.
+Isto, porque *arrays* são objetos. Assim ambas `shoppingCart` e `fruits` são referências para o mesmo *array*.
diff --git a/1-js/05-data-types/04-array/1-item-value/task.md b/1-js/05-data-types/04-array/1-item-value/task.md
index 4fcf384fb..9a8715ae9 100644
--- a/1-js/05-data-types/04-array/1-item-value/task.md
+++ b/1-js/05-data-types/04-array/1-item-value/task.md
@@ -2,18 +2,18 @@ importance: 3
---
-# Is array copied?
+# Foi o *array* copiado?
-What is this code going to show?
+O que irá este código mostrar?
```js
-let fruits = ["Apples", "Pear", "Orange"];
+let fruits = ["Maçã", "Pera", "Laranja"];
-// push a new value into the "copy"
+// adicione um novo valor à "cópia"
let shoppingCart = fruits;
shoppingCart.push("Banana");
-// what's in fruits?
+// o que existe em fruits?
alert( fruits.length ); // ?
```
diff --git a/1-js/05-data-types/04-array/10-maximal-subarray/_js.view/test.js b/1-js/05-data-types/04-array/10-maximal-subarray/_js.view/test.js
index b44e76fe7..2fbd0dada 100644
--- a/1-js/05-data-types/04-array/10-maximal-subarray/_js.view/test.js
+++ b/1-js/05-data-types/04-array/10-maximal-subarray/_js.view/test.js
@@ -1,37 +1,37 @@
describe("getMaxSubSum", function() {
- it("maximal subsum of [1, 2, 3] equals 6", function() {
+ it("máxima subsoma de [1, 2, 3] igual a 6", function() {
assert.equal(getMaxSubSum([1, 2, 3]), 6);
});
- it("maximal subsum of [-1, 2, 3, -9] equals 5", function() {
+ it("máxima subsoma de [-1, 2, 3, -9] igual a 5", function() {
assert.equal(getMaxSubSum([-1, 2, 3, -9]), 5);
});
- it("maximal subsum of [-1, 2, 3, -9, 11] equals 11", function() {
+ it("máxima subsoma de [-1, 2, 3, -9, 11] igual a 11", function() {
assert.equal(getMaxSubSum([-1, 2, 3, -9, 11]), 11);
});
- it("maximal subsum of [-2, -1, 1, 2] equals 3", function() {
+ it("máxima subsoma de [-2, -1, 1, 2] igual a 3", function() {
assert.equal(getMaxSubSum([-2, -1, 1, 2]), 3);
});
- it("maximal subsum of [100, -9, 2, -3, 5] equals 100", function() {
+ it("máxima subsoma de [100, -9, 2, -3, 5] igual a 100", function() {
assert.equal(getMaxSubSum([100, -9, 2, -3, 5]), 100);
});
- it("maximal subsum of [] equals 0", function() {
+ it("máxima subsoma de [] igual a 0", function() {
assert.equal(getMaxSubSum([]), 0);
});
- it("maximal subsum of [-1] equals 0", function() {
+ it("máxima subsoma de [-1] igual a 0", function() {
assert.equal(getMaxSubSum([-1]), 0);
});
- it("maximal subsum of [-1, -2] equals 0", function() {
+ it("máxima subsoma de [-1, -2] igual a 0", function() {
assert.equal(getMaxSubSum([-1, -2]), 0);
});
- it("maximal subsum of [2, -8, 5, -1, 2, -3, 2] equals 6", function() {
+ it("máxima subsoma de [2, -8, 5, -1, 2, -3, 2] igual a 6", function() {
assert.equal(getMaxSubSum([2, -8, 5, -1, 2, -3, 2]), 6);
});
});
diff --git a/1-js/05-data-types/04-array/10-maximal-subarray/solution.md b/1-js/05-data-types/04-array/10-maximal-subarray/solution.md
index 7e1ca3bde..baeb9fd0a 100644
--- a/1-js/05-data-types/04-array/10-maximal-subarray/solution.md
+++ b/1-js/05-data-types/04-array/10-maximal-subarray/solution.md
@@ -1,43 +1,43 @@
-# Slow solution
+# Solução lenta
-We can calculate all possible subsums.
+Nós podemos calcular todas as possíveis subsomas.
-The simplest way is to take every element and calculate sums of all subarrays starting from it.
+A forma mais simples será tomar cada elemento e calcular as somas de todos os *subarrays* que comecem por ele.
-For instance, for `[-1, 2, 3, -9, 11]`:
+Por exemplo, para `[-1, 2, 3, -9, 11]`:
```js no-beautify
-// Starting from -1:
+// Começando por -1:
-1
-1 + 2
-1 + 2 + 3
-1 + 2 + 3 + (-9)
-1 + 2 + 3 + (-9) + 11
-// Starting from 2:
+// Começando por 2:
2
2 + 3
2 + 3 + (-9)
2 + 3 + (-9) + 11
-// Starting from 3:
+// Começando por 3:
3
3 + (-9)
3 + (-9) + 11
-// Starting from -9
+// Começando por -9
-9
-9 + 11
-// Starting from 11
+// Começando por 11
11
```
-The code is actually a nested loop: the external loop over array elements, and the internal counts subsums starting with the current element.
+Na verdade, o código é um laço aninhado (*nested loop*): o externo percorre os elementos do *array*, e o interno calcula as subsomas que começam pelo elemento corrente.
```js run
function getMaxSubSum(arr) {
- let maxSum = 0; // if we take no elements, zero will be returned
+ let maxSum = 0; // se não tomarmos nenhum elemento, zero será retornado
for (let i = 0; i < arr.length; i++) {
let sumFixedStart = 0;
@@ -57,25 +57,25 @@ alert( getMaxSubSum([1, 2, 3]) ); // 6
alert( getMaxSubSum([100, -9, 2, -3, 5]) ); // 100
```
-The solution has a time complexity of [O(n2)](https://en.wikipedia.org/wiki/Big_O_notation). In other words, if we increase the array size 2 times, the algorithm will work 4 times longer.
+A solução tem um tempo de complexidade de [O(n2)](https://pt.wikipedia.org/wiki/Grande-O). Por outras palavras, se aumentarmos o tamanho do *array* para o dobro, o algoritmo demorará 4 vezes mais.
-For big arrays (1000, 10000 or more items) such algorithms can lead to serious sluggishness.
+Para grandes *arrays* (1000, 10000 ou mais itens) tais algoritmos podem levar a sérias lentidões.
-# Fast solution
+# Solução rápida
-Let's walk the array and keep the current partial sum of elements in the variable `s`. If `s` becomes negative at some point, then assign `s=0`. The maximum of all such `s` will be the answer.
+Vamos percorrer o *array* e guardar a corrente soma partial dos elementos na variável `s`. Se, a certa altura, `s` se tornar negativo, então faça a atribuição `s=0`. O máximo de todos os `s` será a resposta.
-If the description is too vague, please see the code, it's short enough:
+Se a descrição for demasiado vaga, por favor veja o código, é realmente curto:
```js run demo
function getMaxSubSum(arr) {
let maxSum = 0;
let partialSum = 0;
- for (let item of arr) { // for each item of arr
- partialSum += item; // add it to partialSum
- maxSum = Math.max(maxSum, partialSum); // remember the maximum
- if (partialSum < 0) partialSum = 0; // zero if negative
+ for (let item of arr) { // por cada item de arr
+ partialSum += item; // adicione-o a partialSum ('s' na descrição)
+ maxSum = Math.max(maxSum, partialSum); // guarde o máximo
+ if (partialSum < 0) partialSum = 0; // zero se negativo
}
return maxSum;
@@ -89,6 +89,6 @@ alert( getMaxSubSum([1, 2, 3]) ); // 6
alert( getMaxSubSum([-1, -2, -3]) ); // 0
```
-The algorithm requires exactly 1 array pass, so the time complexity is O(n).
+O algoritmo requere exatamente 1 passagem pelo *array*, portanto o tempo de complexidade é O(n).
-You can find more detailed information about the algorithm here: [Maximum subarray problem](http://en.wikipedia.org/wiki/Maximum_subarray_problem). If it's still not obvious why that works, then please trace the algorithm on the examples above, see how it works, that's better than any words.
+Pode encontrar informação mais detalhada sobre o algoritmo aqui: [Sublista contígua de soma máxima](https://pt.wikipedia.org/wiki/Sublista_cont%C3%ADgua_de_soma_m%C3%A1xima). Se, ainda não for óbvio porque isso funciona, então por favor rasteie o algoritmo nos exemplos acima e veja como trabalha, é melhor do que quaisquer palavras.
diff --git a/1-js/05-data-types/04-array/10-maximal-subarray/task.md b/1-js/05-data-types/04-array/10-maximal-subarray/task.md
index f1a1d9f95..e2b9b12c7 100644
--- a/1-js/05-data-types/04-array/10-maximal-subarray/task.md
+++ b/1-js/05-data-types/04-array/10-maximal-subarray/task.md
@@ -2,29 +2,29 @@ importance: 2
---
-# A maximal subarray
+# Um *subarray* máximo
-The input is an array of numbers, e.g. `arr = [1, -2, 3, 4, -9, 6]`.
+A entrada é um *array* de números, ex. `arr = [1, -2, 3, 4, -9, 6]`.
-The task is: find the contiguous subarray of `arr` with the maximal sum of items.
+A tarefa é: encontrar o contíguo *subarray* de `arr` com a máxima soma de itens.
-Write the function `getMaxSubSum(arr)` that will return that sum.
+Escreva a função `getMaxSubSum(arr)` que irá retornar essa soma.
-For instance:
+Por exemplo:
```js
-getMaxSubSum([-1, *!*2, 3*/!*, -9]) == 5 (the sum of highlighted items)
+getMaxSubSum([-1, *!*2, 3*/!*, -9]) == 5 (a soma dos itens em destaque)
getMaxSubSum([*!*2, -1, 2, 3*/!*, -9]) == 6
getMaxSubSum([-1, 2, 3, -9, *!*11*/!*]) == 11
getMaxSubSum([-2, -1, *!*1, 2*/!*]) == 3
getMaxSubSum([*!*100*/!*, -9, 2, -3, 5]) == 100
-getMaxSubSum([*!*1, 2, 3*/!*]) == 6 (take all)
+getMaxSubSum([*!*1, 2, 3*/!*]) == 6 (tome todos)
```
-If all items are negative, it means that we take none (the subarray is empty), so the sum is zero:
+Se todos os itens forem negativos, significa que não tomamos nenhum (o *subarray* está vazio), então a soma é zero:
```js
getMaxSubSum([-1, -2, -3]) = 0
```
-Please try to think of a fast solution: [O(n2)](https://en.wikipedia.org/wiki/Big_O_notation) or even O(n) if you can.
+Por favor, tente pensar numa solução rápida: [O(n2)](https://pt.wikipedia.org/wiki/Grande-O), ou mesmo O(n) se puder.
diff --git a/1-js/05-data-types/04-array/2-create-array/solution.md b/1-js/05-data-types/04-array/2-create-array/solution.md
index f032b55f0..cde5b72b1 100644
--- a/1-js/05-data-types/04-array/2-create-array/solution.md
+++ b/1-js/05-data-types/04-array/2-create-array/solution.md
@@ -3,7 +3,7 @@
```js run
let styles = ["Jazz", "Blues"];
styles.push("Rock-n-Roll");
-styles[Math.floor((styles.length - 1) / 2)] = "Classics";
+styles[Math.floor((styles.length - 1) / 2)] = "Clássicos";
alert( styles.shift() );
styles.unshift("Rap", "Reggae");
```
diff --git a/1-js/05-data-types/04-array/2-create-array/task.md b/1-js/05-data-types/04-array/2-create-array/task.md
index d4551c79c..811005b2d 100644
--- a/1-js/05-data-types/04-array/2-create-array/task.md
+++ b/1-js/05-data-types/04-array/2-create-array/task.md
@@ -2,23 +2,23 @@ importance: 5
---
-# Array operations.
+# Operações com *arrays*.
-Let's try 5 array operations.
+Vamos tentar 5 operações com *arrays*.
-1. Create an array `styles` with items "Jazz" and "Blues".
-2. Append "Rock-n-Roll" to the end.
-3. Replace the value in the middle with "Classics". Your code for finding the middle value should work for any arrays with odd length.
-4. Strip off the first value of the array and show it.
-5. Prepend `Rap` and `Reggae` to the array.
+1. Crie um *array* `styles` com os itens "Jazz" e "Blues".
+2. Adicione "Rock-n-Roll" ao fim.
+3. Substitua o valor do meio por "Clássicos". O seu código, para encontrar o valor do meio, deverá funcionar para quaisquer *arrays* com um comprimento ímpar.
+4. Elimine o primeiro valor do *array* e o mostre.
+5. Adicione `Rap` e `Reggae` ao inicio do *array*.
-The array in the process:
+O *array* ao longo do processo:
```js no-beautify
Jazz, Blues
Jazz, Blues, Rock-n-Roll
-Jazz, Classics, Rock-n-Roll
-Classics, Rock-n-Roll
-Rap, Reggae, Classics, Rock-n-Roll
+Jazz, Clássicos, Rock-n-Roll
+Clássicos, Rock-n-Roll
+Rap, Reggae, Clássicos, Rock-n-Roll
```
diff --git a/1-js/05-data-types/04-array/3-call-array-this/solution.md b/1-js/05-data-types/04-array/3-call-array-this/solution.md
index 3cb0317cf..82af1cc9b 100644
--- a/1-js/05-data-types/04-array/3-call-array-this/solution.md
+++ b/1-js/05-data-types/04-array/3-call-array-this/solution.md
@@ -1,6 +1,6 @@
-The call `arr[2]()` is syntactically the good old `obj[method]()`, in the role of `obj` we have `arr`, and in the role of `method` we have `2`.
+A chamada `arr[2]()` é sintaticamente a antiga `obj[method]()`; no papel de `obj` temos `arr`, e no papel de `method` temos `2`.
-So we have a call of the function `arr[2]` as an object method. Naturally, it receives `this` referencing the object `arr` and outputs the array:
+Assim, temos uma chamada da função `arr[2]` como um método de objeto. Naturalmente, como ela recebe em `this` a referência ao objeto `arr`, ela exibe o *array*:
```js run
let arr = ["a", "b"];
@@ -12,4 +12,4 @@ arr.push(function() {
arr[2](); // a,b,function(){...}
```
-The array has 3 values: initially it had two, plus the function.
+O *array* tem 3 valores: inicialmente tinha dois, e a função foi adicionada.
diff --git a/1-js/05-data-types/04-array/3-call-array-this/task.md b/1-js/05-data-types/04-array/3-call-array-this/task.md
index f1e13499c..2e2a571f3 100644
--- a/1-js/05-data-types/04-array/3-call-array-this/task.md
+++ b/1-js/05-data-types/04-array/3-call-array-this/task.md
@@ -2,9 +2,9 @@ importance: 5
---
-# Calling in an array context
+# Chamando uma função no contexto de um *array*
-What is the result? Why?
+Qual é o resultado? Porquê?
```js
let arr = ["a", "b"];
diff --git a/1-js/05-data-types/04-array/5-array-input-sum/solution.md b/1-js/05-data-types/04-array/5-array-input-sum/solution.md
index 75bd683b5..68067ab23 100644
--- a/1-js/05-data-types/04-array/5-array-input-sum/solution.md
+++ b/1-js/05-data-types/04-array/5-array-input-sum/solution.md
@@ -1,4 +1,4 @@
-Please note the subtle, but important detail of the solution. We don't convert `value` to number instantly after `prompt`, because after `value = +value` we would not be able to tell an empty string (stop sign) from the zero (valid number). We do it later instead.
+Por favor repare nos subtis, mas importantes detalhes da solução. Nós não convertemos `value` para número imediatamente após `prompt`, porque depois de `value = +value` não teríamos como ver a diferença entre uma *string* vazia (o sinal para parar) e zero (um número válido). Assim, nós o fazemos mais tarde.
```js run demo
@@ -8,9 +8,9 @@ function sumInput() {
while (true) {
- let value = prompt("A number please?", 0);
+ let value = prompt("Um número, por favor?", 0);
- // should we cancel?
+ // nós devemos cancelar?
if (value === "" || value === null || !isFinite(value)) break;
numbers.push(+value);
@@ -23,6 +23,6 @@ function sumInput() {
return sum;
}
-alert( sumInput() );
+alert( sumInput() );
```
diff --git a/1-js/05-data-types/04-array/5-array-input-sum/task.md b/1-js/05-data-types/04-array/5-array-input-sum/task.md
index 4af8e7c95..5567a77d3 100644
--- a/1-js/05-data-types/04-array/5-array-input-sum/task.md
+++ b/1-js/05-data-types/04-array/5-array-input-sum/task.md
@@ -2,14 +2,14 @@ importance: 4
---
-# Sum input numbers
+# Some números entrados pelo usuário
-Write the function `sumInput()` that:
+Escreva a função `sumInput()` que:
-- Asks the user for values using `prompt` and stores the values in the array.
-- Finishes asking when the user enters a non-numeric value, an empty string, or presses "Cancel".
-- Calculates and returns the sum of array items.
+- Peça ao usuário por valores usando `prompt`, e os guarde num *array*.
+- Não peça mais quando o utilizador fornecer um valor não-numérico, uma *string* vazia, ou pressione "*Cancel*".
+- Calcule e retorne a soma dos itens no *array*.
-P.S. A zero `0` is a valid number, please don't stop the input on zero.
+P.S. Um zero `0` é um número válido, por favor não pare de pedir com zero.
[demo]
diff --git a/1-js/05-data-types/04-array/article.md b/1-js/05-data-types/04-array/article.md
index 4bcab0bc9..43eaba06c 100644
--- a/1-js/05-data-types/04-array/article.md
+++ b/1-js/05-data-types/04-array/article.md
@@ -1,320 +1,320 @@
-# Arrays
+# *Arrays*
-Objects allow you to store keyed collections of values. That's fine.
+Objetos permitem-lhe armazenar coleções de valores por chaves. É bom.
-But quite often we find that we need an *ordered collection*, where we have a 1st, a 2nd, a 3rd element and so on. For example, we need that to store a list of something: users, goods, HTML elements etc.
+Mas, frequentemente precisamos de uma *coleção ordenada*, onde tenhamos um 1º, 2º, 3º elemento e assim por diante. Por exemplo, precisamos dela para armazenar uma lista de algo como: visitantes, bens, elementos de HTML, etc.
-It is not convenient to use an object here, because it provides no methods to manage the order of elements. We can’t insert a new property “between” the existing ones. Objects are just not meant for such use.
+Não é conveniente usar um objeto aqui, porque ele não dispõe de métodos para gerir a ordem dos elementos. Não podemos inserir uma nova propriedade “entre” outras já existentes. Objetos simplesmente não são adequados a tal uso.
-There exists a special data structure named `Array`, to store ordered collections.
+Existe uma estrutura de dados especial chamada `Array`, para armazenar coleções ordenadas.
-## Declaration
+## Declaração
-There are two syntaxes for creating an empty array:
+Existem duas sintaxes para criar um *array* vazio:
```js
let arr = new Array();
let arr = [];
```
-Almost all the time, the second syntax is used. We can supply initial elements in the brackets:
+Quase sempre é usada a segunda sintaxe. Também podemos fornecer elementos iniciais entre os parênteses retos:
```js
-let fruits = ["Apple", "Orange", "Plum"];
+let fruits = ["Maçã", "Laranja", "Ameixa"];
```
-Array elements are numbered, starting with zero.
+Os elementos de um *array* são numerados, começando por zero.
-We can get an element by its number in square brackets:
+Podemos obter um elemento fornecendo a sua posição entre parênteses retos:
```js run
-let fruits = ["Apple", "Orange", "Plum"];
+let fruits = ["Maçã", "Laranja", "Ameixa"];
-alert( fruits[0] ); // Apple
-alert( fruits[1] ); // Orange
-alert( fruits[2] ); // Plum
+alert( fruits[0] ); // Maçã
+alert( fruits[1] ); // Laranja
+alert( fruits[2] ); // Ameixa
```
-We can replace an element:
+Podemos substituir um elemento:
```js
-fruits[2] = 'Pear'; // now ["Apple", "Orange", "Pear"]
+fruits[2] = 'Pera'; // now ["Maçã", "Laranja", "Pera"]
```
-...Or add a new one to the array:
+...Ou adicionar um novo ao *array*:
```js
-fruits[3] = 'Lemon'; // now ["Apple", "Orange", "Pear", "Lemon"]
+fruits[3] = 'Limão'; // now ["Maçã", "Laranja", "Pera", "Limão"]
```
-The total count of the elements in the array is its `length`:
+O número total dos elementos no *array* é o seu comprimento (`length`):
```js run
-let fruits = ["Apple", "Orange", "Plum"];
+let fruits = ["Maçã", "Laranja", "Ameixa"];
alert( fruits.length ); // 3
```
-We can also use `alert` to show the whole array.
+Podemos também usar `alert` para exibir todo o *array*.
```js run
-let fruits = ["Apple", "Orange", "Plum"];
+let fruits = ["Maçã", "Laranja", "Ameixa"];
-alert( fruits ); // Apple,Orange,Plum
+alert( fruits ); // Maçã,Laranja,Ameixa
```
-An array can store elements of any type.
+Um *array* pode armazenar elementos de qualquer tipo.
-For instance:
+Por exemplo:
```js run no-beautify
-// mix of values
-let arr = [ 'Apple', { name: 'John' }, true, function() { alert('hello'); } ];
+// mistura de valores
+let arr = [ 'Maçã', { name: 'John' }, true, function() { alert('olá'); } ];
-// get the object at index 1 and then show its name
+// obtenha o objeto no índice 1 e a seguir mostre o seu nome
alert( arr[1].name ); // John
-// get the function at index 3 and run it
-arr[3](); // hello
+// obtenha a função no índice 3 e a execute
+arr[3](); // olá
```
-````smart header="Trailing comma"
-An array, just like an object, may end with a comma:
+````smart header="Vírgula final"
+Um array, tal como um objeto, pode terminar por uma vírgula:
```js
let fruits = [
- "Apple",
- "Orange",
- "Plum"*!*,*/!*
+ "Maçã",
+ "Laranja",
+ "Ameixa"*!*,*/!*
];
```
-The "trailing comma" style makes it easier to insert/remove items, because all lines become alike.
+O estilo de "vírgula final" torna mais fácil inserir/remover itens, porque todas as linhas se tornam semelhantes.
````
-## Get last elements with "at"
+## Obtenha o último elemento com "at"
[recent browser="new"]
-Let's say we want the last element of the array.
+Digamos que queremos o último elemento do *array*.
-Some programming languages allow to use negative indexes for the same purpose, like `fruits[-1]`.
+Algumas linguagens de programação permitem o uso de indices negativos para este propósito, como `fruits[-1]`.
-Although, in JavaScript it won't work. The result will be `undefined`, because the index in square brackets is treated literally.
+Mas, em JavaScript isto não funciona. O resultado irá ser `undefined`, porque um índice entre parenteses retos é tratado literalmente.
-We can explicitly calculate the last element index and then access it: `fruits[fruits.length - 1]`.
+Podemos explicitamente calcular o índice do último elemento, e depois o aceder: `fruits[fruits.length - 1]`.
```js run
-let fruits = ["Apple", "Orange", "Plum"];
+let fruits = ["Maçã", "Laranja", "Ameixa"];
-alert( fruits[fruits.length-1] ); // Plum
+alert( fruits[fruits.length-1] ); // Ameixa
```
-A bit cumbersome, isn't it? We need to write the variable name twice.
+Um pouco complicado, não? Nós precisamos de escrever o nome da variável duas vezes.
-Luckily, there's a shorter syntax: `fruits.at(-1)`:
+Felizmente, existe uma sintaxe mais curta: `fruits.at(-1)`:
```js run
-let fruits = ["Apple", "Orange", "Plum"];
+let fruits = ["Maçã", "Laranja", "Ameixa"];
-// same as fruits[fruits.length-1]
-alert( fruits.at(-1) ); // Plum
+// o mesmo que fruits[fruits.length-1]
+alert( fruits.at(-1) ); // Ameixa
```
-In other words, `arr.at(i)`:
-- is exactly the same as `arr[i]`, if `i >= 0`.
-- for negative values of `i`, it steps back from the end of the array.
+Por outras palavras, `arr.at(i)`:
+- é exatamente o mesmo que `arr[i]`, se `i >= 0`.
+- para valores negativos de `i`, a procura começa pelo fim do *array*.
-## Methods pop/push, shift/unshift
+## Métodos pop/push, shift/unshift
-A [queue](https://en.wikipedia.org/wiki/Queue_(abstract_data_type)) is one of the most common uses of an array. In computer science, this means an ordered collection of elements which supports two operations:
+Uma *fila* ([queue](https://en.wikipedia.org/wiki/Queue_(abstract_data_type))) é um dos usos mais comuns para um *array*. Em ciência dos computadores, ela significa uma coleção ordenada de elementos que suporta duas operações:
-- `push` appends an element to the end.
-- `shift` get an element from the beginning, advancing the queue, so that the 2nd element becomes the 1st.
+- `push` adiciona um elemento ao final.
+- `shift` obtém um elemento do início, avançando a fila, de modo que o 2º elemento se torna no 1º.

-Arrays support both operations.
+Os *arrays* suportam ambas as operações.
-In practice we need it very often. For example, a queue of messages that need to be shown on-screen.
+Na prática, nós a precisamos com muita frequência. Por exemplo, uma fila de mensagens que precisa de ser mostrada no ecrã.
-There's another use case for arrays -- the data structure named [stack](https://en.wikipedia.org/wiki/Stack_(abstract_data_type)).
+Existe um outro caso prático para *arrays* -- a estrutura de dados chamada [pilha](https://pt.wikipedia.org/wiki/Pilha_(inform%C3%A1tica)) (*stack*).
-It supports two operations:
+Ela suporta duas operações:
-- `push` adds an element to the end.
-- `pop` takes an element from the end.
+- `push` adiciona um elemento ao final.
+- `pop` toma um elemento do final.
-So new elements are added or taken always from the "end".
+Assim, novos elementos são sempre adicionados ou tomados do "final".
-A stack is usually illustrated as a pack of cards: new cards are added to the top or taken from the top:
+Uma pilha (*stack*) é geralmente ilustrada como um baralho de cartas: novas cartas são adicionadas ao topo ou tiradas do topo:

-For stacks, the latest pushed item is received first, that's also called LIFO (Last-In-First-Out) principle. For queues, we have FIFO (First-In-First-Out).
+Para pilhas, o último item inserido é recebido primeiro, o que também é chamado de princípio *LIFO* (*Last-In-First-Out*) (o-Último-a-Entrar-é-o-Primeiro-a-Sair). Para filas (*queues*), nós temos *FIFO* (*First-In-First-Out*) (o-Primeiro-a-Entrar-é-o-Primeiro-a-Sair).
-Arrays in JavaScript can work both as a queue and as a stack. They allow you to add/remove elements, both to/from the beginning or the end.
+Os *arrays* em JavaScript tanto podem trabalhar como uma fila, ou como uma pilha. Eles permitem-lhe adicionar/remover elementos quer ao/do início como ao/do final.
-In computer science, the data structure that allows this, is called [deque](https://en.wikipedia.org/wiki/Double-ended_queue).
+Em ciência dos computadores, a estrutura de dados que permite isto é chamada [deque](https://pt.wikipedia.org/wiki/Deque_(estruturas_de_dados)).
-**Methods that work with the end of the array:**
+**Métodos que trabalham no final do _array_:**
`pop`
-: Extracts the last element of the array and returns it:
+: Extrai o último elemento do *array* e o retorna:
```js run
- let fruits = ["Apple", "Orange", "Pear"];
+ let fruits = ["Maçã", "Laranja", "Pera"];
- alert( fruits.pop() ); // remove "Pear" and alert it
+ alert( fruits.pop() ); // remove "Pera" e exibe
- alert( fruits ); // Apple, Orange
+ alert( fruits ); // Maçã, Laranja
```
- Both `fruits.pop()` and `fruits.at(-1)` return the last element of the array, but `fruits.pop()` also modifies the array by removing it.
+Ambos, `fruits.pop()` e `fruits.at(-1)` retornam o último elemento do *array*, mas `fruits.pop()` adicionalmente modifica o *array* removendo-o.
`push`
-: Append the element to the end of the array:
+: Adiciona o elemento ao final do *array*:
```js run
- let fruits = ["Apple", "Orange"];
+ let fruits = ["Maçã", "Laranja"];
- fruits.push("Pear");
+ fruits.push("Pera");
- alert( fruits ); // Apple, Orange, Pear
+ alert( fruits ); // Maçã, Laranja, Pera
```
- The call `fruits.push(...)` is equal to `fruits[fruits.length] = ...`.
+ A chamada `fruits.push(...)` é igual a `fruits[fruits.length] = ...`.
-**Methods that work with the beginning of the array:**
+**Métodos que trabalham no início do _array_:**
`shift`
-: Extracts the first element of the array and returns it:
+: Extrai o primeiro elemento do *array* e o retorna:
- ```js run
- let fruits = ["Apple", "Orange", "Pear"];
+ ```js
+ let fruits = ["Maçã", "Laranja", "Pera"];
- alert( fruits.shift() ); // remove Apple and alert it
+ alert( fruits.shift() ); // remove Maçã e exibe
- alert( fruits ); // Orange, Pear
+ alert( fruits ); // Laranja, Pera
```
`unshift`
-: Add the element to the beginning of the array:
+: Adiciona o elemento ao início do *array*:
- ```js run
- let fruits = ["Orange", "Pear"];
+ ```js
+ let fruits = ["Laranja", "Pera"];
- fruits.unshift('Apple');
+ fruits.unshift('Maçã');
- alert( fruits ); // Apple, Orange, Pear
+ alert( fruits ); // Maçã, Laranja, Pera
```
-Methods `push` and `unshift` can add multiple elements at once:
+Os métodos `push` e `unshift` podem adicionar múltiplos elementos de uma só vez:
```js run
-let fruits = ["Apple"];
+let fruits = ["Maçã"];
-fruits.push("Orange", "Peach");
-fruits.unshift("Pineapple", "Lemon");
+fruits.push("Laranja", "Pêssego");
+fruits.unshift("Ananás", "Limão");
-// ["Pineapple", "Lemon", "Apple", "Orange", "Peach"]
+// ["Ananás", "Limão", "Maçã", "Laranja", "Pêssego"]
alert( fruits );
```
-## Internals
+## Internamente
-An array is a special kind of object. The square brackets used to access a property `arr[0]` actually come from the object syntax. That's essentially the same as `obj[key]`, where `arr` is the object, while numbers are used as keys.
+Um *array* é um tipo especial de objeto. Os parêntesis retos usados para aceder a uma propriedade `arr[0]` vêm, na verdade, da sintaxe de objetos. Isto, é essencialmente o mesmo que `obj[key]`, onde `arr` é o objeto, e números são usados como chaves.
-They extend objects providing special methods to work with ordered collections of data and also the `length` property. But at the core it's still an object.
+Eles são uma extensão aos objetos, fornecendo métodos especiais para trabalhar com coleções ordenadas de dados e também a propriedade `length`. Assim, no seu núcleo um *array* é um objeto.
-Remember, there are only eight basic data types in JavaScript (see the [Data types](info:types) chapter for more info). Array is an object and thus behaves like an object.
+Lembre-se, só existem oito tipos de dados básicos em JavaScript (veja o capítulo [Tipos de dads](info:types) para mais informação). O *array* é um objeto, e portanto comporta-se como um objeto.
-For instance, it is copied by reference:
+Por exemplo, ele é copiado por referência:
```js run
let fruits = ["Banana"]
-let arr = fruits; // copy by reference (two variables reference the same array)
-
-alert( arr === fruits ); // true
+let arr = fruits; // cópia por referência (duas variáveis referenciam o mesmo array)
-arr.push("Pear"); // modify the array by reference
+alert( arr === fruits ); // true (verdadeiro)
+
+arr.push("Pera"); // modifique o array por referência
-alert( fruits ); // Banana, Pear - 2 items now
+alert( fruits ); // Banana, Pera - 2 itens agora
```
-...But what makes arrays really special is their internal representation. The engine tries to store its elements in the contiguous memory area, one after another, just as depicted on the illustrations in this chapter, and there are other optimizations as well, to make arrays work really fast.
+...Mas, o que torna os *arrays* realmente especiais é a sua representação interna. O interpretador de JavaScript tenta armazenar os seus elementos numa área contígua de memória, um após outro, precisamente como mostrado nas ilustrações deste capítulo, e também existem outras optimizações para fazerem os *arrays* trabalhar verdadeiramente rápido.
-But they all break if we quit working with an array as with an "ordered collection" and start working with it as if it were a regular object.
+Mas, todas elas quebram se pararmos de trabalhar com um *array* como com uma "coleção ordenada", e começarmos a trabalhar com ele como se fosse um objeto regular.
-For instance, technically we can do this:
+Por exemplo, tecnicamente nós podemos fazer isto:
```js
-let fruits = []; // make an array
+let fruits = []; // cria um array
-fruits[99999] = 5; // assign a property with the index far greater than its length
+fruits[99999] = 5; // atribui uma propriedade com um índice muito maior do que o comprimento do *array*
-fruits.age = 25; // create a property with an arbitrary name
+fruits.age = 25; // cria uma propriedade com um nome arbitrário
```
-That's possible, because arrays are objects at their base. We can add any properties to them.
+Isso é possível, porque *arrays* são objetos na sua base. Podemos adicionar quaisquer propriedades a eles.
-But the engine will see that we're working with the array as with a regular object. Array-specific optimizations are not suited for such cases and will be turned off, their benefits disappear.
+Mas, o interpretador irá ver que nós estamos a trabalhar com o *array* como com um objeto regular. Optimizações especificas para *arrays* não são adequadas a tais casos e serão desativadas, os seus benefícios desaparecem.
-The ways to misuse an array:
+Formas de má utilização de um *array*:
-- Add a non-numeric property like `arr.test = 5`.
-- Make holes, like: add `arr[0]` and then `arr[1000]` (and nothing between them).
-- Fill the array in the reverse order, like `arr[1000]`, `arr[999]` and so on.
+- Adicionar uma propriedade não-numérica, como `arr.test = 5`.
+- Formar buracos, como: adicionar `arr[0]` e depois `arr[1000]` (e nada entre eles).
+- Preencher o *array* por ordem inversa, como `arr[1000]`, `arr[999]` e assim por diante.
-Please think of arrays as special structures to work with the *ordered data*. They provide special methods for that. Arrays are carefully tuned inside JavaScript engines to work with contiguous ordered data, please use them this way. And if you need arbitrary keys, chances are high that you actually require a regular object `{}`.
+Por favor, pense em *arrays* como estruturas especiais para trabalhar com *dados ordenados*. Eles fornecem métodos especiais para isso. *Arrays* são cuidadosamente afinados dentro dos interpretadores de JavaScript (*JavaScript engines*) para trabalharem com dados ordenados contíguos, por favor os utilize desta forma. E, se precisar de chaves arbitrárias, são altas as chances de que na verdade necessite de um objeto regular `{}`.
## Performance
-Methods `push/pop` run fast, while `shift/unshift` are slow.
+Os métodos `push/pop` correm rapidamente, enquanto `shift/unshift` são lentos.

-Why is it faster to work with the end of an array than with its beginning? Let's see what happens during the execution:
+Porque é mais rápido trabalhar no final de um *array*, do que no seu início? Vejamos o que acontece durante a execução:
```js
-fruits.shift(); // take 1 element from the start
+fruits.shift(); // tome 1 elemento do início
```
-It's not enough to take and remove the element with the index `0`. Other elements need to be renumbered as well.
+Não é suficiente tomar e remover o elemento com o índice `0`. Os outros elementos também precisam de ser reposicionados.
-The `shift` operation must do 3 things:
+A operação `shift` deve efetuar 3 coisas:
-1. Remove the element with the index `0`.
-2. Move all elements to the left, renumber them from the index `1` to `0`, from `2` to `1` and so on.
-3. Update the `length` property.
+1. Remover o elemento com o índice `0`.
+2. Mover todos os elementos para a esquerda, renumerando-os do índice `1` para `0`, do `2` para `1`, e assim por diante.
+3. Atualizar a propriedade `length`.

-**The more elements in the array, the more time to move them, more in-memory operations.**
+**Quantos mais elementos no *array*, mais tempo se leva para os mover, e mais operações em memória.**
-The similar thing happens with `unshift`: to add an element to the beginning of the array, we need first to move existing elements to the right, increasing their indexes.
+A semelhança acontece com `unshift`: para adicionar um elemento ao início do *array*, nós primeiro precisamos de mover os elementos existentes para a direita, aumentando os seus indices.
-And what's with `push/pop`? They do not need to move anything. To extract an element from the end, the `pop` method cleans the index and shortens `length`.
+E, o que se passa com `push/pop`? Eles, não precisam de mover nada. Para extrair um elemento do final, o método `pop` limpa o índice e diminui `length`.
-The actions for the `pop` operation:
+As ações para a operação `pop`:
```js
-fruits.pop(); // take 1 element from the end
+fruits.pop(); // tome 1 elemento do final
```

-**The `pop` method does not need to move anything, because other elements keep their indexes. That's why it's blazingly fast.**
+**O método `pop` não precisa de mover nada, porque os outros elementos mantêm os seus indices. É por isso que é extremamente rápido.**
-The similar thing with the `push` method.
+O semelhante se passa com o método `push`.
-## Loops
+## *Loops*
-One of the oldest ways to cycle array items is the `for` loop over indexes:
+Uma das velhas formas para percorrer itens de um *array*, é o ciclo `for` sobre os seus indices:
```js run
-let arr = ["Apple", "Orange", "Pear"];
+let arr = ["Maçã", "Laranja", "Pera"];
*!*
for (let i = 0; i < arr.length; i++) {
@@ -323,101 +323,101 @@ for (let i = 0; i < arr.length; i++) {
}
```
-But for arrays there is another form of loop, `for..of`:
+Mas, para *arrays* existe ainda um outro ciclo, o `for..of`:
```js run
-let fruits = ["Apple", "Orange", "Plum"];
+let fruits = ["Maçã", "Laranja", "Ameixa"];
-// iterates over array elements
+// itera sobre os elementos do array
for (let fruit of fruits) {
alert( fruit );
}
```
-The `for..of` doesn't give access to the number of the current element, just its value, but in most cases that's enough. And it's shorter.
+O `for..of` não dá acesso ao índice do elemento atual, mas apenas ao seu valor, contudo em muitos casos é o suficiente. E a sintaxe é mais curta.
-Technically, because arrays are objects, it is also possible to use `for..in`:
+Tecnicamente, uma vez que *arrays* são objetos, também é possível usar `for..in`:
```js run
-let arr = ["Apple", "Orange", "Pear"];
+let arr = ["Maçã", "Laranja", "Pera"];
*!*
for (let key in arr) {
*/!*
- alert( arr[key] ); // Apple, Orange, Pear
+ alert( arr[key] ); // Maçã, Laranja, Pera
}
```
-But that's actually a bad idea. There are potential problems with it:
+Mas, na verdade é uma má ideia. Existem potenciais problemas com isso:
-1. The loop `for..in` iterates over *all properties*, not only the numeric ones.
+1. O ciclo `for..in` itera sobre *todas as propriedades*, não apenas sobre as numéricas.
- There are so-called "array-like" objects in the browser and in other environments, that *look like arrays*. That is, they have `length` and indexes properties, but they may also have other non-numeric properties and methods, which we usually don't need. The `for..in` loop will list them though. So if we need to work with array-like objects, then these "extra" properties can become a problem.
+ Existem os objetos chamados de "semelhantes-a-arrays" (*array-like*), no navegador e em outros ambientes, que *se parecem com arrays*. Isto é, eles têm as propriedades `length` e indices, mas também podem ter outras propriedades não-numéricas e métodos, que geralmente não precisamos. Contudo, o ciclo `for..in` irá listar todas elas. Assim, se precisarmos de trabalhar com objetos semelhantes-a-arrays, aí essas propriedades "extra" podem constituir um problema.
-2. The `for..in` loop is optimized for generic objects, not arrays, and thus is 10-100 times slower. Of course, it's still very fast. The speedup may only matter in bottlenecks. But still we should be aware of the difference.
+2. O laço (*loop*) `for..in` está optimizado para objetos genéricos, não *arrays*, e desta forma é 10-100 vezes mais lento. Claro que ainda assim é muito rápido. A velocidade pode apenas ser importante em pontos cruciais (*bottlenecks*). Mas, devemos estar conscientes desta diferença.
-Generally, we shouldn't use `for..in` for arrays.
+Em geral, não deveríamos usar `for..in` para *arrays*.
-## A word about "length"
+## Uma palavra sobre "comprimento"
-The `length` property automatically updates when we modify the array. To be precise, it is actually not the count of values in the array, but the greatest numeric index plus one.
+A propriedade `length` (comprimento) é automaticamente atualizada quando nós modificamos o *array*. Para ser preciso, na verdade ela não é a contagem dos valores no *array*, mas sim o maior índice numérico mais um.
-For instance, a single element with a large index gives a big length:
+Por exemplo, um único elemento com um índice alto conduz a um comprimento grande:
```js run
let fruits = [];
-fruits[123] = "Apple";
+fruits[123] = "Maçã";
alert( fruits.length ); // 124
```
-Note that we usually don't use arrays like that.
+Note que geralmente nós não usamos *arrays* desta forma.
-Another interesting thing about the `length` property is that it's writable.
+Uma outra coisa interessante sobre a propriedade `length`, é que pode ser alterada.
-If we increase it manually, nothing interesting happens. But if we decrease it, the array is truncated. The process is irreversible, here's the example:
+Se a aumentarmos manualmente, nada de interessante acontece. Mas, se nós a diminuirmos, o *array* é truncado. O processo é irreversível, e aqui está um exemplo:
```js run
let arr = [1, 2, 3, 4, 5];
-arr.length = 2; // truncate to 2 elements
+arr.length = 2; // trunque para 2 elementos
alert( arr ); // [1, 2]
-arr.length = 5; // return length back
-alert( arr[3] ); // undefined: the values do not return
+arr.length = 5; // retorna o comprimento de volta
+alert( arr[3] ); // undefined: os valores não reaparecem
```
-So, the simplest way to clear the array is: `arr.length = 0;`.
+Assim, a forma mais simples para limpar um array é: `arr.length = 0;`.
## new Array() [#new-array]
-There is one more syntax to create an array:
+Há mais uma sintaxe para se criar um *array*:
```js
-let arr = *!*new Array*/!*("Apple", "Pear", "etc");
+let arr = *!*new Array*/!*("Maçã", "Pera", "etc");
```
-It's rarely used, because square brackets `[]` are shorter. Also, there's a tricky feature with it.
+Raramente é usada, porque os parênteses retos são mais curtos `[]`. Além disso, existe uma característica peculiar a acompanhá-la.
-If `new Array` is called with a single argument which is a number, then it creates an array *without items, but with the given length*.
+Se `new Array` for chamada com um único argumento e sendo este numérico, então ela cria um *array* *sem itens, mas com esse comprimento*.
-Let's see how one can shoot themselves in the foot:
+Vejamos como alguém pode se atraiçoar a si próprio:
```js run
-let arr = new Array(2); // will it create an array of [2] ?
+let arr = new Array(2); // irá criar um array como [2] ?
-alert( arr[0] ); // undefined! no elements.
+alert( arr[0] ); // 'undefined!' nenhum elemento.
-alert( arr.length ); // length 2
+alert( arr.length ); // comprimento 2
```
-To avoid such surprises, we usually use square brackets, unless we really know what we're doing.
+Para evitar tais surpresas, nós geralmente utilizamos parênteses retos, a não ser que realmente saibamos o que estamos a fazer.
-## Multidimensional arrays
+## *Arrays* multidimensionais
-Arrays can have items that are also arrays. We can use it for multidimensional arrays, for example to store matrices:
+*Arrays* podem ter itens que também sejam arrays. Podemos os usar em *arrays* multidimensionais, por exemplo para armazenar matrizes:
```js run
let matrix = [
@@ -426,24 +426,24 @@ let matrix = [
[7, 8, 9]
];
-alert( matrix[1][1] ); // 5, the central element
+alert( matrix[1][1] ); // o elemento central
```
## toString
-Arrays have their own implementation of `toString` method that returns a comma-separated list of elements.
+Os *arrays* têm a sua própria implementação do método `toString`, que retorna uma lista de elementos separados por vírgulas.
-For instance:
+Por exemplo:
```js run
let arr = [1, 2, 3];
alert( arr ); // 1,2,3
-alert( String(arr) === '1,2,3' ); // true
+alert( String(arr) === '1,2,3' ); // true (verdadeiro)
```
-Also, let's try this:
+De igual modo, vamos tentar isto:
```js run
alert( [] + 1 ); // "1"
@@ -451,9 +451,9 @@ alert( [1] + 1 ); // "11"
alert( [1,2] + 1 ); // "1,21"
```
-Arrays do not have `Symbol.toPrimitive`, neither a viable `valueOf`, they implement only `toString` conversion, so here `[]` becomes an empty string, `[1]` becomes `"1"` and `[1,2]` becomes `"1,2"`.
+*Arrays* não têm `Symbol.toPrimitive`, nem um `valueOf` útil, eles apenas implementam a conversão `toString`, e assim `[]` se transforma numa *string* vazia, `[1]` se transforma em `"1"` e `[1,2]` em `"1,2"`.
-When the binary plus `"+"` operator adds something to a string, it converts it to a string as well, so the next step looks like this:
+Quando o operador mais `"+"` binário adiciona algo a uma *string*, ele também converte esse elemento para *string*, e assim os passos anteriores se parecem com:
```js run
alert( "" + 1 ); // "1"
@@ -461,31 +461,31 @@ alert( "1" + 1 ); // "11"
alert( "1,2" + 1 ); // "1,21"
```
-## Don't compare arrays with ==
+## Não compare arrays com ==
-Arrays in JavaScript, unlike some other programming languages, shouldn't be compared with operator `==`.
+Os *arrays* em JavaScript, ao contrário de algumas outras linguagens de programação, não devem ser comparados com o operador `==`.
-This operator has no special treatment for arrays, it works with them as with any objects.
+Este operador não dispõe de um tratamento especial para *arrays*, ele trabalha com eles como com quaisquer objetos.
-Let's recall the rules:
+Vamos nos recordar das regras:
-- Two objects are equal `==` only if they're references to the same object.
-- If one of the arguments of `==` is an object, and the other one is a primitive, then the object gets converted to primitive, as explained in the chapter .
-- ...With an exception of `null` and `undefined` that equal `==` each other and nothing else.
+- Dois objetos são iguais `==` apenas se eles referenciam o mesmo objeto.
+- Se um dos argumentos de `==` for um objeto, e o outro um primitivo, então o objeto é convertido para primitivo, como explicado no capítulo .
+- ...Com a exceção de `null` e `undefined` que se igualam `==` entre si e a nada mais.
-The strict comparison `===` is even simpler, as it doesn't convert types.
+A comparação exata (*strict*) `===` é ainda mais simples, porque ela não converte tipos.
-So, if we compare arrays with `==`, they are never the same, unless we compare two variables that reference exactly the same array.
+Assim, se nós compararmos *arrays* com `==`, eles nunca são iguais, a não ser que comparemos duas variáveis que referenciam exatamente o mesmo *array*.
-For example:
+Por exemplo:
```js run
alert( [] == [] ); // false
alert( [0] == [0] ); // false
```
-These arrays are technically different objects. So they aren't equal. The `==` operator doesn't do item-by-item comparison.
+Estes *arrays* tecnicamente são objetos diferentes. Então, eles não são iguais. O operador `==` não faz uma comparação item-por-item.
-Comparison with primitives may give seemingly strange results as well:
+A comparação com primitivos também pode dar resultados aparentemente estranhos:
```js run
alert( 0 == [] ); // true
@@ -493,59 +493,59 @@ alert( 0 == [] ); // true
alert('0' == [] ); // false
```
-Here, in both cases, we compare a primitive with an array object. So the array `[]` gets converted to primitive for the purpose of comparison and becomes an empty string `''`.
+Aqui, em ambos os casos, nós comparamos um primitivo a um objeto *array*. Assim, o *array* `[]` é convertido para primitivo para os propósitos da comparação e se transforma numa *string* vazia `''`.
-Then the comparison process goes on with the primitives, as described in the chapter :
+Então, a comparação continua entre primitivos, como é descrita no capítulo :
```js run
-// after [] was converted to ''
-alert( 0 == '' ); // true, as '' becomes converted to number 0
+// depois de [] ser convertido para ''
+alert( 0 == '' ); // true, como '' é convertida para 0
-alert('0' == '' ); // false, no type conversion, different strings
+alert('0' == '' ); // false, nenhuma conversão de tipos de dados, apenas strings diferentes
```
-So, how to compare arrays?
+Então, como comparar *arrays*?
-That's simple: don't use the `==` operator. Instead, compare them item-by-item in a loop or using iteration methods explained in the next chapter.
+Isto é simples: não use o operador `==`. Em vez disto, os compare item-por-item num laço (*loop*) ou usando métodos de iteração explicados no próximo capítulo.
-## Summary
+## Sumário
-Array is a special kind of object, suited to storing and managing ordered data items.
+O *array* é um tipo especial de objeto, apropriado para armazenar e gerir itens de dados ordenados.
-The declaration:
+A declaração:
```js
-// square brackets (usual)
+// parênteses retos (usual)
let arr = [item1, item2...];
-// new Array (exceptionally rare)
+// new Array (excepcionalmente rara)
let arr = new Array(item1, item2...);
```
-The call to `new Array(number)` creates an array with the given length, but without elements.
+A chamada a `new Array(number)` cria um *array* com o comprimento dado, mas sem elementos.
-- The `length` property is the array length or, to be precise, its last numeric index plus one. It is auto-adjusted by array methods.
-- If we shorten `length` manually, the array is truncated.
+- A propriedade `length` é o comprimento do *array* ou, para ser preciso, o seu último índice numérico mais um. Ela é auto-ajustada por métodos do *array*.
+- Se nós encurtarmos `length` manualmente, o *array* é truncado.
-Getting the elements:
+Obtendo os elementos:
-- we can get element by its index, like `arr[0]`
-- also we can use `at(i)` method that allows negative indexes. For negative values of `i`, it steps back from the end of the array. If `i >= 0`, it works same as `arr[i]`.
+- nós podemos obter o elemento por meio do seu índice, como `arr[0]`
+- também podemos usar o método `at(i)`, que permite indices negativos. Para valores negativos de `i`, a procura começa pelo fim do array. Se `i >= 0`, funciona como `arr[i]`.
-We can use an array as a deque with the following operations:
+Podemos usar um *array* como uma *deque* (estrutura de dados), com as seguintes operações:
-- `push(...items)` adds `items` to the end.
-- `pop()` removes the element from the end and returns it.
-- `shift()` removes the element from the beginning and returns it.
-- `unshift(...items)` adds `items` to the beginning.
+- `push(...items)` adiciona `items` ao final.
+- `pop()` remove o elemento do final, e o retorna.
+- `shift()` remove o elemento do início, e o retorna.
+- `unshift(...items)` adiciona `items` ao início.
-To loop over the elements of the array:
- - `for (let i=0; i`, `<` and others), as they have no special treatment for arrays. They handle them as any objects, and it's not what we usually want.
+Para comparar *arrays*, não use o operador `==` (como também `>`, `<` ou outros), porque eles não dispõem de tratamento especial para *arrays*. Eles os tratam como quaisquer objetos, mas não é o que geralmente queremos.
-Instead you can use `for..of` loop to compare arrays item-by-item.
+No seu lugar, você pode usar o laço `for..of` para comparar *arrays* item-por-item.
-We will continue with arrays and study more methods to add, remove, extract elements and sort arrays in the next chapter .
+Nós voltaremos aos *arrays*, e estudaremos mais métodos para adicionar, remover, extrair elementos e os ordenar no capítulo .