chore(i18n,curriculum): update translations (#43089)
This commit is contained in:
@ -1,6 +1,6 @@
|
||||
---
|
||||
id: a3f503de51cf954ede28891d
|
||||
title: Find the Symmetric Difference
|
||||
title: Encontrar a diferença simétrica
|
||||
challengeType: 5
|
||||
forumTopicId: 301611
|
||||
dashedName: find-the-symmetric-difference
|
||||
@ -8,77 +8,77 @@ dashedName: find-the-symmetric-difference
|
||||
|
||||
# --description--
|
||||
|
||||
The mathematical term <dfn>symmetric difference</dfn> (`△` or `⊕`) of two sets is the set of elements which are in either of the two sets but not in both. For example, for sets `A = {1, 2, 3}` and `B = {2, 3, 4}`, `A △ B = {1, 4}`.
|
||||
O termo matemático <dfn>diferença simétrica</dfn> (`△` ou `⊕`) de dois conjuntos é o conjunto de elementos que estão em um dos dois conjuntos, mas não em ambos. Por exemplo, para os conjuntos `A = {1, 2, 3}` e `B = {2, 3, 4}`, `A △ B = {1, 4}`.
|
||||
|
||||
Symmetric difference is a binary operation, which means it operates on only two elements. So to evaluate an expression involving symmetric differences among *three* elements (`A △ B △ C`), you must complete one operation at a time. Thus, for sets `A` and `B` above, and `C = {2, 3}`, `A △ B △ C = (A △ B) △ C = {1, 4} △ {2, 3} = {1, 2, 3, 4}`.
|
||||
A diferença simétrica é uma operação binária, o que significa que opera em apenas dois elementos. Assim, para avaliar uma expressão que envolva diferenças simétricas entre *três* elementos (`A △ B △ C`), você deve completar uma operação por vez. Portanto, para os conjuntos `A` e `B` acima, e `C = {2, 3}`, `A △ B △ C = (A △ B) △ C = {1, 4} △ {2, 3} = {1, 2, 3, 4}`.
|
||||
|
||||
# --instructions--
|
||||
|
||||
Create a function that takes two or more arrays and returns an array of their symmetric difference. The returned array must contain only unique values (*no duplicates*).
|
||||
Crie uma função que receba dois ou mais arrays e retorne um array de sua diferença simétrica. O array retornado deve conter apenas valores únicos (*sem duplicatas*).
|
||||
|
||||
# --hints--
|
||||
|
||||
`sym([1, 2, 3], [5, 2, 1, 4])` should return `[3, 4, 5]`.
|
||||
`sym([1, 2, 3], [5, 2, 1, 4])` deve retornar `[3, 4, 5]`.
|
||||
|
||||
```js
|
||||
assert.sameMembers(sym([1, 2, 3], [5, 2, 1, 4]), [3, 4, 5]);
|
||||
```
|
||||
|
||||
`sym([1, 2, 3], [5, 2, 1, 4])` should contain only three elements.
|
||||
`sym([1, 2, 3], [5, 2, 1, 4])` deve conter apenas três elementos.
|
||||
|
||||
```js
|
||||
assert.equal(sym([1, 2, 3], [5, 2, 1, 4]).length, 3);
|
||||
```
|
||||
|
||||
`sym([1, 2, 3, 3], [5, 2, 1, 4])` should return `[3, 4, 5]`.
|
||||
`sym([1, 2, 3, 3], [5, 2, 1, 4])` deve retornar `[3, 4, 5]`.
|
||||
|
||||
```js
|
||||
assert.sameMembers(sym([1, 2, 3, 3], [5, 2, 1, 4]), [3, 4, 5]);
|
||||
```
|
||||
|
||||
`sym([1, 2, 3, 3], [5, 2, 1, 4])` should contain only three elements.
|
||||
`sym([1, 2, 3, 3], [5, 2, 1, 4])` deve conter apenas três elementos.
|
||||
|
||||
```js
|
||||
assert.equal(sym([1, 2, 3, 3], [5, 2, 1, 4]).length, 3);
|
||||
```
|
||||
|
||||
`sym([1, 2, 3], [5, 2, 1, 4, 5])` should return `[3, 4, 5]`.
|
||||
`sym([1, 2, 3], [5, 2, 1, 4, 5])` deve retornar `[3, 4, 5]`.
|
||||
|
||||
```js
|
||||
assert.sameMembers(sym([1, 2, 3], [5, 2, 1, 4, 5]), [3, 4, 5]);
|
||||
```
|
||||
|
||||
`sym([1, 2, 3], [5, 2, 1, 4, 5])` should contain only three elements.
|
||||
`sym([1, 2, 3], [5, 2, 1, 4, 5])` deve conter apenas três elementos.
|
||||
|
||||
```js
|
||||
assert.equal(sym([1, 2, 3], [5, 2, 1, 4, 5]).length, 3);
|
||||
```
|
||||
|
||||
`sym([1, 2, 5], [2, 3, 5], [3, 4, 5])` should return `[1, 4, 5]`
|
||||
`sym([1, 2, 5], [2, 3, 5], [3, 4, 5])` deve retornar `[1, 4, 5]`
|
||||
|
||||
```js
|
||||
assert.sameMembers(sym([1, 2, 5], [2, 3, 5], [3, 4, 5]), [1, 4, 5]);
|
||||
```
|
||||
|
||||
`sym([1, 2, 5], [2, 3, 5], [3, 4, 5])` should contain only three elements.
|
||||
`sym([1, 2, 5], [2, 3, 5], [3, 4, 5])` deve conter apenas três elementos.
|
||||
|
||||
```js
|
||||
assert.equal(sym([1, 2, 5], [2, 3, 5], [3, 4, 5]).length, 3);
|
||||
```
|
||||
|
||||
`sym([1, 1, 2, 5], [2, 2, 3, 5], [3, 4, 5, 5])` should return `[1, 4, 5]`.
|
||||
`sym([1, 1, 2, 5], [2, 2, 3, 5], [3, 4, 5, 5])` deve retornar `[1, 4, 5]`.
|
||||
|
||||
```js
|
||||
assert.sameMembers(sym([1, 1, 2, 5], [2, 2, 3, 5], [3, 4, 5, 5]), [1, 4, 5]);
|
||||
```
|
||||
|
||||
`sym([1, 1, 2, 5], [2, 2, 3, 5], [3, 4, 5, 5])` should contain only three elements.
|
||||
`sym([1, 1, 2, 5], [2, 2, 3, 5], [3, 4, 5, 5])` deve conter apenas três elementos.
|
||||
|
||||
```js
|
||||
assert.equal(sym([1, 1, 2, 5], [2, 2, 3, 5], [3, 4, 5, 5]).length, 3);
|
||||
```
|
||||
|
||||
`sym([3, 3, 3, 2, 5], [2, 1, 5, 7], [3, 4, 6, 6], [1, 2, 3])` should return `[2, 3, 4, 6, 7]`.
|
||||
`sym([3, 3, 3, 2, 5], [2, 1, 5, 7], [3, 4, 6, 6], [1, 2, 3])` deve retornar `[2, 3, 4, 6, 7]`.
|
||||
|
||||
```js
|
||||
assert.sameMembers(
|
||||
@ -87,7 +87,7 @@ assert.sameMembers(
|
||||
);
|
||||
```
|
||||
|
||||
`sym([3, 3, 3, 2, 5], [2, 1, 5, 7], [3, 4, 6, 6], [1, 2, 3])` should contain only five elements.
|
||||
`sym([3, 3, 3, 2, 5], [2, 1, 5, 7], [3, 4, 6, 6], [1, 2, 3])` deve conter apenas cinco elementos.
|
||||
|
||||
```js
|
||||
assert.equal(
|
||||
@ -96,7 +96,7 @@ assert.equal(
|
||||
);
|
||||
```
|
||||
|
||||
`sym([3, 3, 3, 2, 5], [2, 1, 5, 7], [3, 4, 6, 6], [1, 2, 3], [5, 3, 9, 8], [1])` should return `[1, 2, 4, 5, 6, 7, 8, 9]`.
|
||||
`sym([3, 3, 3, 2, 5], [2, 1, 5, 7], [3, 4, 6, 6], [1, 2, 3], [5, 3, 9, 8], [1])` deve retornar `[1, 2, 4, 5, 6, 7, 8, 9]`.
|
||||
|
||||
```js
|
||||
assert.sameMembers(
|
||||
@ -112,7 +112,7 @@ assert.sameMembers(
|
||||
);
|
||||
```
|
||||
|
||||
`sym([3, 3, 3, 2, 5], [2, 1, 5, 7], [3, 4, 6, 6], [1, 2, 3], [5, 3, 9, 8], [1])` should contain only eight elements.
|
||||
`sym([3, 3, 3, 2, 5], [2, 1, 5, 7], [3, 4, 6, 6], [1, 2, 3], [5, 3, 9, 8], [1])` deve conter apenas oito elementos.
|
||||
|
||||
```js
|
||||
assert.equal(
|
||||
|
@ -1,6 +1,6 @@
|
||||
---
|
||||
id: 8d5123c8c441eddfaeb5bdef
|
||||
title: Implement Bubble Sort
|
||||
title: Implementar o Bubble Sort
|
||||
challengeType: 1
|
||||
forumTopicId: 301612
|
||||
dashedName: implement-bubble-sort
|
||||
@ -8,23 +8,23 @@ dashedName: implement-bubble-sort
|
||||
|
||||
# --description--
|
||||
|
||||
This is the first of several challenges on sorting algorithms. Given an array of unsorted items, we want to be able to return a sorted array. We will see several different methods to do this and learn some tradeoffs between these different approaches. While most modern languages have built-in sorting methods for operations like this, it is still important to understand some of the common basic approaches and learn how they can be implemented.
|
||||
Este é o primeiro de vários desafios sobre algoritmos de ordenação. Dado um array de itens não ordenados, queremos poder retornar um array ordenado. Veremos vários métodos diferentes para fazer isso e aprenderemos algumas escolhas que precisam ser feitas na hora de usar estas abordagens diferentes. Embora as linguagens mais modernas tenham métodos de ordenação incorporados para operações como esta, continua importante entender algumas das abordagens básicas comuns e aprender como podem ser implementadas.
|
||||
|
||||
Here we will see bubble sort. The bubble sort method starts at the beginning of an unsorted array and 'bubbles up' unsorted values towards the end, iterating through the array until it is completely sorted. It does this by comparing adjacent items and swapping them if they are out of order. The method continues looping through the array until no swaps occur at which point the array is sorted.
|
||||
Aqui, veremos o Bubble Sort. O método do Bubble Sort começa no início de um array não classificado e lança valores não classificados para o fim, iterando através do array até que esteja completamente ordenado. Ele faz isso comparando os itens adjacentes e trocando-os de lugar se eles estiverem fora de ordem. O método continua se repetindo por todo o array até que não ocorram mais trocas, momento em que o array estará ordenado.
|
||||
|
||||
This method requires multiple iterations through the array and for average and worst cases has quadratic time complexity. While simple, it is usually impractical in most situations.
|
||||
Este método requer múltiplas iterações através do array e, em média e nos piores casos, tem complexidade de tempo quadrática. Embora seja simples, ele não é muito prático na maioria das situações.
|
||||
|
||||
**Instructions:** Write a function `bubbleSort` which takes an array of integers as input and returns an array of these integers in sorted order from least to greatest.
|
||||
**Instruções:** escreva uma função `bubbleSort` que receba um array de inteiros como entrada e retorne um array de inteiros ordenado do menor para o maior.
|
||||
|
||||
# --hints--
|
||||
|
||||
`bubbleSort` should be a function.
|
||||
`bubbleSort` deve ser uma função.
|
||||
|
||||
```js
|
||||
assert(typeof bubbleSort == 'function');
|
||||
```
|
||||
|
||||
`bubbleSort` should return a sorted array (least to greatest).
|
||||
`bubbleSort` deve retornar um array ordenado (do menor para o maior elemento).
|
||||
|
||||
```js
|
||||
assert(
|
||||
@ -52,7 +52,7 @@ assert(
|
||||
);
|
||||
```
|
||||
|
||||
`bubbleSort` should return an array that is unchanged except for order.
|
||||
`bubbleSort([1,4,2,8,345,123,43,32,5643,63,123,43,2,55,1,234,92])` deve retornar um array inalterado, exceto por sua ordenação.
|
||||
|
||||
```js
|
||||
assert.sameMembers(
|
||||
@ -79,7 +79,7 @@ assert.sameMembers(
|
||||
);
|
||||
```
|
||||
|
||||
`bubbleSort` should not use the built-in `.sort()` method.
|
||||
`bubbleSort` não deve usar o método `.sort()` integrado.
|
||||
|
||||
```js
|
||||
assert(isBuiltInSortUsed());
|
||||
@ -113,8 +113,6 @@ function bubbleSort(array) {
|
||||
return array;
|
||||
// Only change code above this line
|
||||
}
|
||||
|
||||
bubbleSort([1, 4, 2, 8, 345, 123, 43, 32, 5643, 63, 123, 43, 2, 55, 1, 234, 92]);
|
||||
```
|
||||
|
||||
# --solutions--
|
||||
|
@ -1,6 +1,6 @@
|
||||
---
|
||||
id: 587d8259367417b2b2512c86
|
||||
title: Implement Insertion Sort
|
||||
title: Implementar o Insertion Sort
|
||||
challengeType: 1
|
||||
forumTopicId: 301613
|
||||
dashedName: implement-insertion-sort
|
||||
@ -8,19 +8,19 @@ dashedName: implement-insertion-sort
|
||||
|
||||
# --description--
|
||||
|
||||
The next sorting method we'll look at is insertion sort. This method works by building up a sorted array at the beginning of the list. It begins the sorted array with the first element. Then it inspects the next element and swaps it backwards into the sorted array until it is in sorted position. It continues iterating through the list and swapping new items backwards into the sorted portion until it reaches the end. This algorithm has quadratic time complexity in the average and worst cases.
|
||||
O próximo método de ordenação que analisaremos é o Insertion Sort. Este método funciona criando um array classificado no início da lista. Ele inicia o array ordenado com o primeiro elemento. Depois, ele inspeciona o próximo elemento e o lança para trás no array ordenado até ficar em posição ordenada. Ele continua iterando pela lista e trocando novos itens para trás na porção ordenada até chegar ao final. Este algoritmo apresenta complexidade de tempo quadrática em média e nos piores casos.
|
||||
|
||||
**Instructions:** Write a function `insertionSort` which takes an array of integers as input and returns an array of these integers in sorted order from least to greatest.
|
||||
**Instruções:** escreva uma função `insertionSort` que receba um array de inteiros como entrada e retorne um array de inteiros ordenado do menor para o maior.
|
||||
|
||||
# --hints--
|
||||
|
||||
`insertionSort` should be a function.
|
||||
`insertionSort` deve ser uma função.
|
||||
|
||||
```js
|
||||
assert(typeof insertionSort == 'function');
|
||||
```
|
||||
|
||||
`insertionSort` should return a sorted array (least to greatest).
|
||||
`insertionSort` deve retornar um array ordenado (do menor para o maior elemento).
|
||||
|
||||
```js
|
||||
assert(
|
||||
@ -48,7 +48,7 @@ assert(
|
||||
);
|
||||
```
|
||||
|
||||
`insertionSort` should return an array that is unchanged except for order.
|
||||
`insertionSort([1,4,2,8,345,123,43,32,5643,63,123,43,2,55,1,234,92])` deve retornar um array inalterado, exceto por sua ordenação.
|
||||
|
||||
```js
|
||||
assert.sameMembers(
|
||||
@ -75,7 +75,7 @@ assert.sameMembers(
|
||||
);
|
||||
```
|
||||
|
||||
`insertionSort` should not use the built-in `.sort()` method.
|
||||
`insertionSort` não deve usar o método `.sort()` integrado.
|
||||
|
||||
```js
|
||||
assert(isBuiltInSortUsed());
|
||||
@ -109,8 +109,6 @@ function insertionSort(array) {
|
||||
return array;
|
||||
// Only change code above this line
|
||||
}
|
||||
|
||||
insertionSort([1, 4, 2, 8, 345, 123, 43, 32, 5643, 63, 123, 43, 2, 55, 1, 234, 92]);
|
||||
```
|
||||
|
||||
# --solutions--
|
||||
|
@ -1,6 +1,6 @@
|
||||
---
|
||||
id: 587d825c367417b2b2512c8f
|
||||
title: Implement Merge Sort
|
||||
title: Implementar o Merge Sort
|
||||
challengeType: 1
|
||||
forumTopicId: 301614
|
||||
dashedName: implement-merge-sort
|
||||
@ -8,27 +8,27 @@ dashedName: implement-merge-sort
|
||||
|
||||
# --description--
|
||||
|
||||
Another common intermediate sorting algorithm is merge sort. Like quick sort, merge sort also uses a divide-and-conquer, recursive methodology to sort an array. It takes advantage of the fact that it is relatively easy to sort two arrays as long as each is sorted in the first place. But we'll start with only one array as input, so how do we get to two sorted arrays from that? Well, we can recursively divide the original input in two until we reach the base case of an array with one item. A single-item array is naturally sorted, so then we can start combining. This combination will unwind the recursive calls that split the original array, eventually producing a final sorted array of all the elements. The steps of merge sort, then, are:
|
||||
Outro algoritmo de ordenação intermediária comum é o Merge Sort. Assim como ocorre com o Quick Sort, o Merge Sort também usa uma metodologia de dividir e conquistar e recursiva para ordenar um array. Ele leva vantagem pelo fato de ser relativamente fácil ordenar dois arrays desde que cada um esteja ordenado, para começar. Começaremos com apenas um array como entrada. Então, como podemos obter dois arrays ordenados a partir disso? Bem, podemos dividir recursivamente a entrada original em duas até chegarmos ao caso de base de um array com um único item. Um array de item único está naturalmente ordenado. Então, podemos começar a combinar. Esta combinação revelará as chamadas recursivas que dividem o array original, no fim produzindo um array de todos os elementos. As etapas do Merge Sort são, portanto:
|
||||
|
||||
**1)** Recursively split the input array in half until a sub-array with only one element is produced.
|
||||
**1)** Dividir recursivamente o array de entrada ao meio até ser produzido um subarray com apenas um elemento.
|
||||
|
||||
**2)** Merge each sorted sub-array together to produce the final sorted array.
|
||||
**2)** Combinar e unir cada subarray ordenado para produzir o array com a ordenação final.
|
||||
|
||||
Merge sort is an efficient sorting method, with time complexity of *O(nlog(n))*. This algorithm is popular because it is performant and relatively easy to implement.
|
||||
O Merge Sort é um método eficiente de ordenação, com complexidade de tempo de *O(nlog(n))*. Este algoritmo é popular porque tem boa performance e é relativamente fácil de implementar.
|
||||
|
||||
As an aside, this will be the last sorting algorithm we cover here. However, later in the section on tree data structures we will describe heap sort, another efficient sorting method that requires a binary heap in its implementation.
|
||||
Este será o último algoritmo de ordenação do qual trataremos aqui. No entanto, mais tarde, na seção sobre estruturas de dados em árvore, descreveremos o Heap Sort, outro método de classificação eficiente que requer uma pilha binária (binary heap) em sua implementação.
|
||||
|
||||
**Instructions:** Write a function `mergeSort` which takes an array of integers as input and returns an array of these integers in sorted order from least to greatest. A good way to implement this is to write one function, for instance `merge`, which is responsible for merging two sorted arrays, and another function, for instance `mergeSort`, which is responsible for the recursion that produces single-item arrays to feed into merge. Good luck!
|
||||
**Instruções:** escreva uma função `mergeSort` que receba um array de inteiros como entrada e retorne um array de inteiros ordenado do menor para o maior. Uma boa maneira de implementá-la é escrever uma função, por exemplo `merge`, que seja responsável por mesclar dois arrays ordenados, e outra função, por exemplo, `mergeSort`, que seja responsável pela recursão que produz arrays de um único item para alimentar a função merge. Boa sorte!
|
||||
|
||||
# --hints--
|
||||
|
||||
`mergeSort` should be a function.
|
||||
`mergeSort` deve ser uma função.
|
||||
|
||||
```js
|
||||
assert(typeof mergeSort == 'function');
|
||||
```
|
||||
|
||||
`mergeSort` should return a sorted array (least to greatest).
|
||||
`mergeSort` deve retornar um array ordenado (do menor para o maior elemento).
|
||||
|
||||
```js
|
||||
assert(
|
||||
@ -56,7 +56,7 @@ assert(
|
||||
);
|
||||
```
|
||||
|
||||
`mergeSort` should return an array that is unchanged except for order.
|
||||
`mergeSort([1,4,2,8,345,123,43,32,5643,63,123,43,2,55,1,234,92])` deve retornar um array inalterado, exceto por sua ordenação.
|
||||
|
||||
```js
|
||||
assert.sameMembers(
|
||||
@ -83,7 +83,7 @@ assert.sameMembers(
|
||||
);
|
||||
```
|
||||
|
||||
`mergeSort` should not use the built-in `.sort()` method.
|
||||
`mergeSort` não deve usar o método `.sort()` integrado.
|
||||
|
||||
```js
|
||||
assert(isBuiltInSortUsed());
|
||||
@ -117,8 +117,6 @@ function mergeSort(array) {
|
||||
return array;
|
||||
// Only change code above this line
|
||||
}
|
||||
|
||||
mergeSort([1, 4, 2, 8, 345, 123, 43, 32, 5643, 63, 123, 43, 2, 55, 1, 234, 92]);
|
||||
```
|
||||
|
||||
# --solutions--
|
||||
|
@ -1,6 +1,6 @@
|
||||
---
|
||||
id: 587d8259367417b2b2512c85
|
||||
title: Implement Selection Sort
|
||||
title: Implementar o Selection Sort
|
||||
challengeType: 1
|
||||
forumTopicId: 301616
|
||||
dashedName: implement-selection-sort
|
||||
@ -8,19 +8,19 @@ dashedName: implement-selection-sort
|
||||
|
||||
# --description--
|
||||
|
||||
Here we will implement selection sort. Selection sort works by selecting the minimum value in a list and swapping it with the first value in the list. It then starts at the second position, selects the smallest value in the remaining list, and swaps it with the second element. It continues iterating through the list and swapping elements until it reaches the end of the list. Now the list is sorted. Selection sort has quadratic time complexity in all cases.
|
||||
Aqui, implementaremos o Selection Sort. O Selection Sort funciona a partir da seleção do valor mínimo em uma lista e trocando-o de posição com o primeiro valor na lista. Ele, então, começa da segunda posição, seleciona o menor valor da lista restante e troca-o pelo segundo elemento. Ele continua iterando através da lista e trocando elementos até chegar ao final da lista. Agora, a lista estará ordenada. O Selection Sort tem complexidade de tempo quadrática em todos os casos.
|
||||
|
||||
**Instructions**: Write a function `selectionSort` which takes an array of integers as input and returns an array of these integers in sorted order from least to greatest.
|
||||
**Instruções:** escreva uma função `selectionSort` que receba um array de inteiros como entrada e retorne um array de inteiros ordenado do menor para o maior.
|
||||
|
||||
# --hints--
|
||||
|
||||
`selectionSort` should be a function.
|
||||
`selectionSort` deve ser uma função.
|
||||
|
||||
```js
|
||||
assert(typeof selectionSort == 'function');
|
||||
```
|
||||
|
||||
`selectionSort` should return a sorted array (least to greatest).
|
||||
`selectionSort` deve retornar um array ordenado (do menor para o maior elemento).
|
||||
|
||||
```js
|
||||
assert(
|
||||
@ -48,7 +48,7 @@ assert(
|
||||
);
|
||||
```
|
||||
|
||||
`selectionSort` should return an array that is unchanged except for order.
|
||||
`selectionSort([1,4,2,8,345,123,43,32,5643,63,123,43,2,55,1,234,92])` deve retornar um array inalterado, exceto por sua ordenação.
|
||||
|
||||
```js
|
||||
assert.sameMembers(
|
||||
@ -75,7 +75,7 @@ assert.sameMembers(
|
||||
);
|
||||
```
|
||||
|
||||
`selectionSort` should not use the built-in `.sort()` method.
|
||||
`selectionSort` não deve usar o método `.sort()` integrado.
|
||||
|
||||
```js
|
||||
assert(isBuiltInSortUsed());
|
||||
@ -109,9 +109,6 @@ function selectionSort(array) {
|
||||
return array;
|
||||
// Only change code above this line
|
||||
}
|
||||
|
||||
|
||||
selectionSort([1, 4, 2, 8, 345, 123, 43, 32, 5643, 63, 123, 43, 2, 55, 1, 234, 92]);
|
||||
```
|
||||
|
||||
# --solutions--
|
||||
|
@ -1,6 +1,6 @@
|
||||
---
|
||||
id: a56138aff60341a09ed6c480
|
||||
title: Inventory Update
|
||||
title: Atualização de inventário
|
||||
challengeType: 5
|
||||
forumTopicId: 16019
|
||||
dashedName: inventory-update
|
||||
@ -8,11 +8,11 @@ dashedName: inventory-update
|
||||
|
||||
# --description--
|
||||
|
||||
Compare and update the inventory stored in a 2D array against a second 2D array of a fresh delivery. Update the current existing inventory item quantities (in `arr1`). If an item cannot be found, add the new item and quantity into the inventory array. The returned inventory array should be in alphabetical order by item.
|
||||
Compare e atualize o inventário armazenado em um array 2D contrastando-o com um segundo array 2D de uma nova entrega. Atualize as quantidades atuais de itens do inventário (em `arr1`). Se um item não puder ser encontrado, adicione o novo item e sua quantidade no array do inventário. O array do inventário retornado deve estar em ordem alfabética por item.
|
||||
|
||||
# --hints--
|
||||
|
||||
The function `updateInventory` should return an array.
|
||||
A função `updateInventory` deve retornar um array.
|
||||
|
||||
```js
|
||||
assert.isArray(
|
||||
@ -33,7 +33,7 @@ assert.isArray(
|
||||
);
|
||||
```
|
||||
|
||||
`updateInventory([[21, "Bowling Ball"], [2, "Dirty Sock"], [1, "Hair Pin"], [5, "Microphone"]], [[2, "Hair Pin"], [3, "Half-Eaten Apple"], [67, "Bowling Ball"], [7, "Toothpaste"]])` should return an array with a length of 6.
|
||||
`updateInventory([[21, "Bowling Ball"], [2, "Dirty Sock"], [1, "Hair Pin"], [5, "Microphone"]], [[2, "Hair Pin"], [3, "Half-Eaten Apple"], [67, "Bowling Ball"], [7, "Toothpaste"]])` deve retornar um array de tamanho 6.
|
||||
|
||||
```js
|
||||
assert.equal(
|
||||
@ -55,7 +55,7 @@ assert.equal(
|
||||
);
|
||||
```
|
||||
|
||||
`updateInventory([[21, "Bowling Ball"], [2, "Dirty Sock"], [1, "Hair Pin"], [5, "Microphone"]], [[2, "Hair Pin"], [3, "Half-Eaten Apple"], [67, "Bowling Ball"], [7, "Toothpaste"]])` should return `[[88, "Bowling Ball"], [2, "Dirty Sock"], [3, "Hair Pin"], [3, "Half-Eaten Apple"], [5, "Microphone"], [7, "Toothpaste"]]`.
|
||||
`updateInventory([[21, "Bowling Ball"], [2, "Dirty Sock"], [1, "Hair Pin"], [5, "Microphone"]], [[2, "Hair Pin"], [3, "Half-Eaten Apple"], [67, "Bowling Ball"], [7, "Toothpaste"]])` deve retornar `[[88, "Bowling Ball"], [2, "Dirty Sock"], [3, "Hair Pin"], [3, "Half-Eaten Apple"], [5, "Microphone"], [7, "Toothpaste"]]`.
|
||||
|
||||
```js
|
||||
assert.deepEqual(
|
||||
@ -84,7 +84,7 @@ assert.deepEqual(
|
||||
);
|
||||
```
|
||||
|
||||
`updateInventory([[21, "Bowling Ball"], [2, "Dirty Sock"], [1, "Hair Pin"], [5, "Microphone"]], [])` should return `[[21, "Bowling Ball"], [2, "Dirty Sock"], [1, "Hair Pin"], [5, "Microphone"]]`.
|
||||
`updateInventory([[21, "Bowling Ball"], [2, "Dirty Sock"], [1, "Hair Pin"], [5, "Microphone"]], [])` deve retornar `[[21, "Bowling Ball"], [2, "Dirty Sock"], [1, "Hair Pin"], [5, "Microphone"]]`.
|
||||
|
||||
```js
|
||||
assert.deepEqual(
|
||||
@ -106,7 +106,7 @@ assert.deepEqual(
|
||||
);
|
||||
```
|
||||
|
||||
`updateInventory([], [[2, "Hair Pin"], [3, "Half-Eaten Apple"], [67, "Bowling Ball"], [7, "Toothpaste"]])` should return `[[67, "Bowling Ball"], [2, "Hair Pin"], [3, "Half-Eaten Apple"], [7, "Toothpaste"]]`.
|
||||
`updateInventory([], [[2, "Hair Pin"], [3, "Half-Eaten Apple"], [67, "Bowling Ball"], [7, "Toothpaste"]])` deve retornar `[[67, "Bowling Ball"], [2, "Hair Pin"], [3, "Half-Eaten Apple"], [7, "Toothpaste"]]`.
|
||||
|
||||
```js
|
||||
assert.deepEqual(
|
||||
@ -128,7 +128,7 @@ assert.deepEqual(
|
||||
);
|
||||
```
|
||||
|
||||
`updateInventory([[0, "Bowling Ball"], [0, "Dirty Sock"], [0, "Hair Pin"], [0, "Microphone"]], [[1, "Hair Pin"], [1, "Half-Eaten Apple"], [1, "Bowling Ball"], [1, "Toothpaste"]])` should return `[[1, "Bowling Ball"], [0, "Dirty Sock"], [1, "Hair Pin"], [1, "Half-Eaten Apple"], [0, "Microphone"], [1, "Toothpaste"]]`.
|
||||
`updateInventory([[0, "Bowling Ball"], [0, "Dirty Sock"], [0, "Hair Pin"], [0, "Microphone"]], [[1, "Hair Pin"], [1, "Half-Eaten Apple"], [1, "Bowling Ball"], [1, "Toothpaste"]])` deve retornar `[[1, "Bowling Ball"], [0, "Dirty Sock"], [1, "Hair Pin"], [1, "Half-Eaten Apple"], [0, "Microphone"], [1, "Toothpaste"]]`.
|
||||
|
||||
```js
|
||||
assert.deepEqual(
|
||||
|
@ -1,6 +1,6 @@
|
||||
---
|
||||
id: a7bf700cd123b9a54eef01d5
|
||||
title: No Repeats Please
|
||||
title: Sem repetir
|
||||
challengeType: 5
|
||||
forumTopicId: 16037
|
||||
dashedName: no-repeats-please
|
||||
@ -8,67 +8,67 @@ dashedName: no-repeats-please
|
||||
|
||||
# --description--
|
||||
|
||||
Return the number of total permutations of the provided string that don't have repeated consecutive letters. Assume that all characters in the provided string are each unique.
|
||||
Retorne o número de permutações totais da string fornecida que não tenham letras consecutivas repetidas. Pense que todos os caracteres na cadeia fornecida sejam exclusivos.
|
||||
|
||||
For example, `aab` should return 2 because it has 6 total permutations (`aab`, `aab`, `aba`, `aba`, `baa`, `baa`), but only 2 of them (`aba` and `aba`) don't have the same letter (in this case `a`) repeating.
|
||||
Por exemplo, `aab` deve retornar 2, porque tem um total de 6 permutações (`aab`, `aab`, `aba`, `aba`, `baa`, `baa`), mas apenas 2 delas (`aba` e `aba`) não têm a mesma letra (neste caso, `a`) se repetindo.
|
||||
|
||||
# --hints--
|
||||
|
||||
`permAlone("aab")` should return a number.
|
||||
`permAlone("aab")` deve retornar um número.
|
||||
|
||||
```js
|
||||
assert.isNumber(permAlone('aab'));
|
||||
```
|
||||
|
||||
`permAlone("aab")` should return 2.
|
||||
`permAlone("aab")` deve retornar 2.
|
||||
|
||||
```js
|
||||
assert.strictEqual(permAlone('aab'), 2);
|
||||
```
|
||||
|
||||
`permAlone("aaa")` should return 0.
|
||||
`permAlone("aaa")` deve retornar 0.
|
||||
|
||||
```js
|
||||
assert.strictEqual(permAlone('aaa'), 0);
|
||||
```
|
||||
|
||||
`permAlone("aabb")` should return 8.
|
||||
`permAlone("aabb")` deve retornar 8.
|
||||
|
||||
```js
|
||||
assert.strictEqual(permAlone('aabb'), 8);
|
||||
```
|
||||
|
||||
`permAlone("abcdefa")` should return 3600.
|
||||
`permAlone("abcdefa")` deve retornar 3600.
|
||||
|
||||
```js
|
||||
assert.strictEqual(permAlone('abcdefa'), 3600);
|
||||
```
|
||||
|
||||
`permAlone("abfdefa")` should return 2640.
|
||||
`permAlone("abfdefa")` deve retornar 2640.
|
||||
|
||||
```js
|
||||
assert.strictEqual(permAlone('abfdefa'), 2640);
|
||||
```
|
||||
|
||||
`permAlone("zzzzzzzz")` should return 0.
|
||||
`permAlone("zzzzzzzz")` deve retornar 0.
|
||||
|
||||
```js
|
||||
assert.strictEqual(permAlone('zzzzzzzz'), 0);
|
||||
```
|
||||
|
||||
`permAlone("a")` should return 1.
|
||||
`permAlone("a")` deve retornar 1.
|
||||
|
||||
```js
|
||||
assert.strictEqual(permAlone('a'), 1);
|
||||
```
|
||||
|
||||
`permAlone("aaab")` should return 0.
|
||||
`permAlone("aaab")` deve retornar 0.
|
||||
|
||||
```js
|
||||
assert.strictEqual(permAlone('aaab'), 0);
|
||||
```
|
||||
|
||||
`permAlone("aaabb")` should return 12.
|
||||
`permAlone("aaabb")` deve retornar 12.
|
||||
|
||||
```js
|
||||
assert.strictEqual(permAlone('aaabb'), 12);
|
||||
|
@ -1,6 +1,6 @@
|
||||
---
|
||||
id: a3f503de51cfab748ff001aa
|
||||
title: Pairwise
|
||||
title: De par em par
|
||||
challengeType: 5
|
||||
forumTopicId: 301617
|
||||
dashedName: pairwise
|
||||
@ -8,57 +8,57 @@ dashedName: pairwise
|
||||
|
||||
# --description--
|
||||
|
||||
Given an array `arr`, find element pairs whose sum equal the second argument `arg` and return the sum of their indices.
|
||||
Dado um array `arr`, encontre pares de elementos cuja soma seja igual ao segundo argumento `arg` e retorne a soma de seus índices.
|
||||
|
||||
You may use multiple pairs that have the same numeric elements but different indices. Each pair should use the lowest possible available indices. Once an element has been used it cannot be reused to pair with another element. For instance, `pairwise([1, 1, 2], 3)` creates a pair `[2, 1]` using the 1 at index 0 rather than the 1 at index 1, because 0+2 < 1+2.
|
||||
Você pode usar vários pares que tenham os mesmos elementos numéricos, mas com índices diferentes. Cada par deve utilizar os menores índices disponíveis. Quando um elemento tiver sido usado, ele não pode ser reutilizado para fazer par com outro elemento. Por exemplo, `pairwise([1, 1, 2], 3)` cria um par `[2, 1]` usando o 1 no índice 0 ao invés do 1 no índice 1, porque 0+2 < 1+2.
|
||||
|
||||
For example `pairwise([7, 9, 11, 13, 15], 20)` returns `6`. The pairs that sum to 20 are `[7, 13]` and `[9, 11]`. We can then write out the array with their indices and values.
|
||||
Um outro exemplo: `pairwise([7, 9, 11, 13, 15], 20)` retorna `6`. Os pares que somam 20 são `[7, 13]` e `[9, 11]`. Em seguida, podemos escrever o array com seus índices e valores.
|
||||
|
||||
<div style='margin-left: 2em;'>
|
||||
|
||||
| Index | 0 | 1 | 2 | 3 | 4 |
|
||||
| Índice | 0 | 1 | 2 | 3 | 4 |
|
||||
| ----- | - | - | -- | -- | -- |
|
||||
| Value | 7 | 9 | 11 | 13 | 15 |
|
||||
| Valor | 7 | 9 | 11 | 13 | 15 |
|
||||
|
||||
</div>
|
||||
|
||||
Below we'll take their corresponding indices and add them.
|
||||
Abaixo, pegaremos os respectivos índices e os somaremos.
|
||||
|
||||
<div style='margin-left: 2em;'>
|
||||
|
||||
7 + 13 = 20 → Indices 0 + 3 = 3
|
||||
9 + 11 = 20 → Indices 1 + 2 = 3
|
||||
3 + 3 = 6 → Return `6`
|
||||
7 + 13 = 20 → Índices 0 + 3 = 3
|
||||
9 + 11 = 20 → Índices 1 + 2 = 3
|
||||
3 + 3 = 6 → Retorna `6`
|
||||
|
||||
</div>
|
||||
|
||||
# --hints--
|
||||
|
||||
`pairwise([1, 4, 2, 3, 0, 5], 7)` should return 11.
|
||||
`pairwise([1, 4, 2, 3, 0, 5], 7)` deve retornar 11.
|
||||
|
||||
```js
|
||||
assert.deepEqual(pairwise([1, 4, 2, 3, 0, 5], 7), 11);
|
||||
```
|
||||
|
||||
`pairwise([1, 3, 2, 4], 4)` should return 1.
|
||||
`pairwise([1, 3, 2, 4], 4)` deve retornar 1.
|
||||
|
||||
```js
|
||||
assert.deepEqual(pairwise([1, 3, 2, 4], 4), 1);
|
||||
```
|
||||
|
||||
`pairwise([1, 1, 1], 2)` should return 1.
|
||||
`pairwise([1, 1, 1], 2)` deve retornar 1.
|
||||
|
||||
```js
|
||||
assert.deepEqual(pairwise([1, 1, 1], 2), 1);
|
||||
```
|
||||
|
||||
`pairwise([0, 0, 0, 0, 1, 1], 1)` should return 10.
|
||||
`pairwise([0, 0, 0, 0, 1, 1], 1)` deve retornar 10.
|
||||
|
||||
```js
|
||||
assert.deepEqual(pairwise([0, 0, 0, 0, 1, 1], 1), 10);
|
||||
```
|
||||
|
||||
`pairwise([], 100)` should return 0.
|
||||
`pairwise([], 100)` deve retornar 0.
|
||||
|
||||
```js
|
||||
assert.deepEqual(pairwise([], 100), 0);
|
||||
|
Reference in New Issue
Block a user