Skip to content

Arrays - #479

Merged
gabifs merged 2 commits into
javascript-tutorial:masterfrom
diogoosz:translate-arrays
Nov 21, 2026
Merged

Arrays#479
gabifs merged 2 commits into
javascript-tutorial:masterfrom
diogoosz:translate-arrays

Conversation

@diogoosz

@diogoosz diogoosz commented Nov 8, 2026

Copy link
Copy Markdown
Contributor

Tradução do artigo "Arrays" para o português, incluindo os exercícios e as imagens array-pop.svg e array-shift.svg.

Conforme comentado na #1.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Comment thread 1-js/05-data-types/04-array/article.md Outdated
O mesmo vale para o método `push`.

## Loops
## Laços

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Traduzir o título ## Loops para ## Laços muda a âncora gerada, e 1-js/02-first-steps/13-while-for/article.md:17 aponta para info:array#loops, que vai quebrar. Manter a âncora explícita, como no resto do repo (ex.: [#new-array]):

Suggested change
## Laços
## Laços [#loops]

Comment thread 1-js/05-data-types/04-array/article.md Outdated
## Não compare arrays com ==

Arrays in JavaScript, unlike some other programming languages, shouldn't be compared with operator `==`.
Arrays no JavaScript, diferente de outras linguagens de programação, não devem ser comparados com o operador `==`.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

O original diz "unlike some other programming languages". Sem o "algumas", a frase passa a dizer que todas as outras linguagens comparam arrays por valor com ==.

Suggested change
Arrays no JavaScript, diferente de outras linguagens de programação, não devem ser comparados com o operador `==`.
Arrays no JavaScript, diferente de algumas outras linguagens de programação, não devem ser comparados com o operador `==`.

@@ -1 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" width="479" height="148" viewBox="0 0 479 148"><defs><style>@import url(https://fonts.googleapis.com/css?family=Open+Sans:bold,italic,bolditalic%7CPT+Mono);@font-face{font-family:&apos;PT Mono&apos;;font-weight:700;font-style:normal;src:local(&apos;PT MonoBold&apos;),url(/font/PTMonoBold.woff2) format(&apos;woff2&apos;),url(/font/PTMonoBold.woff) format(&apos;woff&apos;),url(/font/PTMonoBold.ttf) format(&apos;truetype&apos;)}</style></defs><g id="array" fill="none" fill-rule="evenodd" stroke="none" stroke-width="1"><g id="array-pop.svg"><path id="Rectangle-1" fill="#FBF2EC" stroke="#DBAF88" stroke-width="2" d="M103 82h35v52h-35z"/><path id="Rectangle-2" fill="#FBF2EC" stroke="#DBAF88" stroke-width="2" d="M139 82h35v52h-35z"/><text id="0" fill="#AF6E24" font-family="PTMono-Regular, PT Mono" font-size="14" font-weight="normal"><tspan x="117" y="112">0</tspan></text><text id="1" fill="#AF6E24" font-family="PTMono-Regular, PT Mono" font-size="14" font-weight="normal"><tspan x="154" y="112">1</tspan></text><path id="Rectangle-3" fill="#FBF2EC" stroke="#DBAF88" stroke-width="2" d="M175 82h35v52h-35z"/><text id="2" fill="#AF6E24" font-family="PTMono-Regular, PT Mono" font-size="14" font-weight="normal"><tspan x="190" y="112">2</tspan></text><path id="Rectangle-4" fill="#FBF2EC" stroke="#DBAF88" stroke-width="2" d="M211 82h35v52h-35z"/><text id="3" fill="#C06334" font-family="PTMono-Regular, PT Mono" font-size="14" font-weight="normal"><tspan x="226" y="112">3</tspan></text><text id="&quot;Apple&quot;" fill="#AF6E24" font-family="PTMono-Regular, PT Mono" font-size="14" font-weight="normal" transform="rotate(-89 114.044 48.948)"><tspan x="84.544" y="53.448">&quot;Apple&quot;</tspan></text><text id="&quot;Orange&quot;" fill="#AF6E24" font-family="PTMono-Regular, PT Mono" font-size="14" font-weight="normal" transform="rotate(-89 151.053 44.448)"><tspan x="117.053" y="48.948">&quot;Orange&quot;</tspan></text><text id="&quot;Pear&quot;" fill="#AF6E24" font-family="PTMono-Regular, PT Mono" font-size="14" font-weight="normal" transform="rotate(-89 187.535 52.448)"><tspan x="162.035" y="56.948">&quot;Pear&quot;</tspan></text><text id="&quot;Lemon&quot;" fill="#C06334" font-family="PTMono-Regular, PT Mono" font-size="14" font-weight="normal" transform="rotate(-89 229.044 48.948)"><tspan x="199.544" y="53.448">&quot;Lemon&quot;</tspan></text><text id="length-=-4" fill="#AF6E24" font-family="PTMono-Regular, PT Mono" font-size="14" font-weight="normal"><tspan x="8" y="59">length = 4</tspan></text><path id="Shape" fill="#C06334" d="M306 137l9-16.606h-6V78h-6v42.394h-6z" transform="rotate(-90 306 107.5)"/><text id="clear" fill="#C06334" font-family="OpenSans-Regular, Open Sans" font-size="14" font-weight="normal"><tspan x="287" y="96">clear</tspan></text><path id="Rectangle-7" fill="#FBF2EC" stroke="#DBAF88" stroke-width="2" d="M363 82h35v52h-35z"/><path id="Rectangle-5" fill="#FBF2EC" stroke="#DBAF88" stroke-width="2" d="M399 82h35v52h-35z"/><text id="-1" fill="#AF6E24" font-family="PTMono-Regular, PT Mono" font-size="14" font-weight="normal"><tspan x="377" y="112">0</tspan></text><text id="-2" fill="#AF6E24" font-family="PTMono-Regular, PT Mono" font-size="14" font-weight="normal"><tspan x="414" y="112">1</tspan></text><path id="Rectangle-6" fill="#FBF2EC" stroke="#DBAF88" stroke-width="2" d="M435 82h35v52h-35z"/><text id="-3" fill="#AF6E24" font-family="PTMono-Regular, PT Mono" font-size="14" font-weight="normal"><tspan x="450" y="112">2</tspan></text><text id="&quot;Apple&quot;" fill="#AF6E24" font-family="PTMono-Regular, PT Mono" font-size="14" font-weight="normal" transform="rotate(-89 374.044 48.948)"><tspan x="344.544" y="53.448">&quot;Apple&quot;</tspan></text><text id="&quot;Orange&quot;" fill="#AF6E24" font-family="PTMono-Regular, PT Mono" font-size="14" font-weight="normal" transform="rotate(-89 411.053 44.448)"><tspan x="377.053" y="48.948">&quot;Orange&quot;</tspan></text><text id="&quot;Pear&quot;" fill="#AF6E24" font-family="PTMono-Regular, PT Mono" font-size="14" font-weight="normal" transform="rotate(-89 447.535 52.448)"><tspan x="422.035" y="56.948">&quot;Pear&quot;</tspan></text><text id="length-=-3" fill="#AF6E24" font-family="PTMono-Regular, PT Mono" font-size="14" font-weight="normal"><tspan x="263" y="59">length = 3</tspan></text></g></g></svg> No newline at end of file
<svg xmlns="http://www.w3.org/2000/svg" width="479" height="148" viewBox="0 0 479 148"><defs><style>@import url(https://fonts.googleapis.com/css?family=Open+Sans:bold,italic,bolditalic%7CPT+Mono);@font-face{font-family:&apos;PT Mono&apos;;font-weight:700;font-style:normal;src:local(&apos;PT MonoBold&apos;),url(/font/PTMonoBold.woff2) format(&apos;woff2&apos;),url(/font/PTMonoBold.woff) format(&apos;woff&apos;),url(/font/PTMonoBold.ttf) format(&apos;truetype&apos;)}</style></defs><g id="array" fill="none" fill-rule="evenodd" stroke="none" stroke-width="1"><g id="array-pop.svg"><path id="Rectangle-1" fill="#FBF2EC" stroke="#DBAF88" stroke-width="2" d="M103 82h35v52h-35z"/><path id="Rectangle-2" fill="#FBF2EC" stroke="#DBAF88" stroke-width="2" d="M139 82h35v52h-35z"/><text id="0" fill="#AF6E24" font-family="PTMono-Regular, PT Mono" font-size="14" font-weight="normal"><tspan x="117" y="112">0</tspan></text><text id="1" fill="#AF6E24" font-family="PTMono-Regular, PT Mono" font-size="14" font-weight="normal"><tspan x="154" y="112">1</tspan></text><path id="Rectangle-3" fill="#FBF2EC" stroke="#DBAF88" stroke-width="2" d="M175 82h35v52h-35z"/><text id="2" fill="#AF6E24" font-family="PTMono-Regular, PT Mono" font-size="14" font-weight="normal"><tspan x="190" y="112">2</tspan></text><path id="Rectangle-4" fill="#FBF2EC" stroke="#DBAF88" stroke-width="2" d="M211 82h35v52h-35z"/><text id="3" fill="#C06334" font-family="PTMono-Regular, PT Mono" font-size="14" font-weight="normal"><tspan x="226" y="112">3</tspan></text><text id="&quot;Apple&quot;" fill="#AF6E24" font-family="PTMono-Regular, PT Mono" font-size="14" font-weight="normal" transform="rotate(-89 114.044 48.948)"><tspan x="84.544" y="53.448">&quot;Apple&quot;</tspan></text><text id="&quot;Orange&quot;" fill="#AF6E24" font-family="PTMono-Regular, PT Mono" font-size="14" font-weight="normal" transform="rotate(-89 151.053 44.448)"><tspan x="117.053" y="48.948">&quot;Orange&quot;</tspan></text><text id="&quot;Pear&quot;" fill="#AF6E24" font-family="PTMono-Regular, PT Mono" font-size="14" font-weight="normal" transform="rotate(-89 187.535 52.448)"><tspan x="162.035" y="56.948">&quot;Pear&quot;</tspan></text><text id="&quot;Lemon&quot;" fill="#C06334" font-family="PTMono-Regular, PT Mono" font-size="14" font-weight="normal" transform="rotate(-89 229.044 48.948)"><tspan x="199.544" y="53.448">&quot;Lemon&quot;</tspan></text><text id="length-=-4" fill="#AF6E24" font-family="PTMono-Regular, PT Mono" font-size="14" font-weight="normal"><tspan x="8" y="59">length = 4</tspan></text><path id="Shape" fill="#C06334" d="M306 137l9-16.606h-6V78h-6v42.394h-6z" transform="rotate(-90 306 107.5)"/><text id="clear" fill="#C06334" font-family="OpenSans-Regular, Open Sans" font-size="14" font-weight="normal"><tspan x="281.5" y="96">limpar</tspan></text><path id="Rectangle-7" fill="#FBF2EC" stroke="#DBAF88" stroke-width="2" d="M363 82h35v52h-35z"/><path id="Rectangle-5" fill="#FBF2EC" stroke="#DBAF88" stroke-width="2" d="M399 82h35v52h-35z"/><text id="-1" fill="#AF6E24" font-family="PTMono-Regular, PT Mono" font-size="14" font-weight="normal"><tspan x="377" y="112">0</tspan></text><text id="-2" fill="#AF6E24" font-family="PTMono-Regular, PT Mono" font-size="14" font-weight="normal"><tspan x="414" y="112">1</tspan></text><path id="Rectangle-6" fill="#FBF2EC" stroke="#DBAF88" stroke-width="2" d="M435 82h35v52h-35z"/><text id="-3" fill="#AF6E24" font-family="PTMono-Regular, PT Mono" font-size="14" font-weight="normal"><tspan x="450" y="112">2</tspan></text><text id="&quot;Apple&quot;" fill="#AF6E24" font-family="PTMono-Regular, PT Mono" font-size="14" font-weight="normal" transform="rotate(-89 374.044 48.948)"><tspan x="344.544" y="53.448">&quot;Apple&quot;</tspan></text><text id="&quot;Orange&quot;" fill="#AF6E24" font-family="PTMono-Regular, PT Mono" font-size="14" font-weight="normal" transform="rotate(-89 411.053 44.448)"><tspan x="377.053" y="48.948">&quot;Orange&quot;</tspan></text><text id="&quot;Pear&quot;" fill="#AF6E24" font-family="PTMono-Regular, PT Mono" font-size="14" font-weight="normal" transform="rotate(-89 447.535 52.448)"><tspan x="422.035" y="56.948">&quot;Pear&quot;</tspan></text><text id="length-=-3" fill="#AF6E24" font-family="PTMono-Regular, PT Mono" font-size="14" font-weight="normal"><tspan x="263" y="59">length = 3</tspan></text></g></g></svg> No newline at end of file

@gabifs gabifs Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Os SVGs (array-pop.svg e array-shift.svg) foram editados à mão, além das entradas no images.yml. Em revisões anteriores (commits f1ad49a e e0bc9bc) pedimos para reverter SVGs editados manualmente e deixar só o images.yml como fonte, porque o pipeline de imagens gera os SVGs traduzidos. Por favor, reverta os dois SVGs para a versão original.

# Solução lenta

We can calculate all possible subsums.
Podemos calcular todas as somas parciais possíveis.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"subsums" virou "somas parciais" aqui e na linha 36, mas o test.js usa "subsoma", e a solução rápida (linha 66) usa "soma parcial" para outro conceito (partialSum, o acumulador que é zerado). O leitor pode confundir as duas ideias. Sugestão: usar "subsomas" de forma consistente.

Suggested change
Podemos calcular todas as somas parciais possíveis.
Podemos calcular todas as subsomas possíveis.

Comment thread 1-js/05-data-types/04-array/article.md Outdated

arr.length = 5; // return length back
alert( arr[3] ); // undefined: the values do not return
arr.length = 5; // retorna o length de volta

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"retorna o length" parece dizer que algo devolve o length. O original ("return length back") quer dizer restaurar o valor.

Suggested change
arr.length = 5; // retorna o length de volta
arr.length = 5; // restaura o length original

## 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](https://en.wikipedia.org/wiki/Queue_(abstract_data_type)) é um dos usos mais comuns de um array. Em ciência da computação, isso significa uma coleção ordenada de elementos que suporta duas operações:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inconsistência nos links: fila continua em en.wikipedia, mas pilha (l.141) e deque (l.158) foram trocados para pt.wikipedia. Vale padronizar e confirmar que os títulos em pt existem (a página de pilha em pt costuma ser "Pilha (informática)").

@@ -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.
Observe o detalhe sutil, mas importante, da solução. Não convertemos `value` para número logo depois do `prompt`, porque depois de `value = +value` não conseguiríamos mais distinguir uma string vazia (sinal de parada) do zero (número válido). Fazemos isso mais tarde, em vez disso.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Redundância: "mais tarde, em vez disso".

Suggested change
Observe o detalhe sutil, mas importante, da solução. Não convertemos `value` para número logo depois do `prompt`, porque depois de `value = +value` não conseguiríamos mais distinguir uma string vazia (sinal de parada) do zero (número válido). Fazemos isso mais tarde, em vez disso.
Observe o detalhe sutil, mas importante, da solução. Não convertemos `value` para número logo depois do `prompt`, porque depois de `value = +value` não conseguiríamos mais distinguir uma string vazia (sinal de parada) do zero (número válido). Em vez disso, fazemos isso mais tarde.

Comment thread 1-js/05-data-types/04-array/article.md Outdated
- 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`.
- Criar buracos, tipo: adicionar `arr[0]` e depois `arr[1000]` (e nada entre eles).
- Preencher o array na ordem reversa, tipo `arr[1000]`, `arr[999]` e assim por diante.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: "tipo" é informal demais para o tom do tutorial (também na linha 267). Sugiro "como".

Suggested change
- Preencher o array na ordem reversa, tipo `arr[1000]`, `arr[999]` e assim por diante.
- Preencher o array na ordem reversa, como `arr[1000]`, `arr[999]` e assim por diante.

- Revert the hand-edited array-pop.svg/array-shift.svg back to the
  original and regenerate them from images.yml via the gulp
  translation pipeline instead, per the project's standing rule of
  never hand-editing SVGs; verified visually that both render
  correctly
- Add explicit anchor [#loops] to "## Laços" so the existing
  <info:array#loops> link from 02-first-steps/13-while-for keeps
  working
- Fix dropped qualifier: "diferente de outras linguagens" (implies
  ALL others compare by value) -> "diferente de algumas outras
  linguagens"
- Fix misleading comment: "retorna o length de volta" (sounds like
  it returns something) -> "restaura o length original"
- Standardize informal "tipo" -> "como" (2 occurrences)
- Standardize "somas parciais" -> "subsomas" in
  10-maximal-subarray/solution.md to match the term used in
  _js.view/test.js, avoiding confusion with "soma parcial" (the
  `partialSum` accumulator, a different concept covered later in the
  same file)
- Fix dangling "mais tarde, em vez disso" -> "em vez disso, fazemos
  isso mais tarde"

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@diogoosz

Copy link
Copy Markdown
Contributor Author

Obrigado, @gabifs! Peço desculpas pela reincidência nos SVGs editados à mão -- revertidos array-pop.svg e array-shift.svg para o original e regenerados via pipeline (images.yml + gulp), conferidos visualmente. Também corrigi: adicionei a âncora [#loops] pra não quebrar o link de 13-while-for, "diferente de outras linguagens"→"diferente de algumas outras linguagens", "retorna o length de volta"→"restaura o length original", "tipo"→"como", "somas parciais"→"subsomas" (consistente com o test.js), e a frase truncada no 5-array-input-sum. Sobre o link da fila: procurei um artigo equivalente em pt.wikipedia.org e não encontrei um bom (só "Fila de prioridade", que é outro conceito, e "Fila de mensagens"), então mantive o link em inglês deliberadamente.

@gabifs
gabifs merged commit 5fa4fe6 into javascript-tutorial:master Nov 21, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants