docs: add Spanish docs

This commit is contained in:
Beau Carnes
2018-10-08 13:34:43 -04:00
parent 46d8d61776
commit fcced4a6c3
912 changed files with 80339 additions and 171 deletions

View File

@ -0,0 +1,95 @@
---
id: a3f503de51cf954ede28891d
title: Find the Symmetric Difference
localeTitle: Encuentra la diferencia simétrica
challengeType: 5
---
## Description
<section id='description'>
Cree una función que tome dos o más matrices y devuelva una matriz de la <dfn>diferencia simétrica</dfn> ( <code></code> o <code></code> ) de las matrices proporcionadas.
Dado dos conjuntos (por ejemplo, conjunto <code>A = {1, 2, 3}</code> y conjunto <code>B = {2, 3, 4}</code> ), el término matemático &quot;diferencia simétrica&quot; es el conjunto de elementos que se encuentran en cualquiera de los dos conjuntos, pero no en ambos ( <code>A △ B = C = {1, 4}</code> ). Por cada diferencia simétrica adicional que tome (por ejemplo, en un conjunto <code>D = {2, 3}</code> ), debe obtener el conjunto con elementos que están en cualquiera de los dos conjuntos pero no en ambos ( <code>C △ D = {1, 4} △ {2, 3} = {1, 2, 3, 4}</code> ). La matriz resultante debe contener solo valores únicos ( <em>no duplicados</em> ).
Recuerda usar <a href='http://forum.freecodecamp.org/t/how-to-get-help-when-you-are-stuck/19514' target='_blank'>Read-Search-Ask</a> si te atascas. Trate de emparejar el programa. Escribe tu propio código.
</section>
## Instructions
<section id='instructions'>
</section>
## Tests
<section id='tests'>
```yml
tests:
- text: &#39; <code>sym([1, 2, 3], [5, 2, 1, 4])</code> debe devolver <code>[3, 4, 5]</code> .&#39;
testString: 'assert.sameMembers(sym([1, 2, 3], [5, 2, 1, 4]), [3, 4, 5], "<code>sym([1, 2, 3], [5, 2, 1, 4])</code> should return <code>[3, 4, 5]</code>.");'
- text: &#39; <code>sym([1, 2, 3], [5, 2, 1, 4])</code> debe contener solo tres elementos.&#39;
testString: 'assert.equal(sym([1, 2, 3], [5, 2, 1, 4]).length, 3, "<code>sym([1, 2, 3], [5, 2, 1, 4])</code> should contain only three elements.");'
- text: &#39; <code>sym([1, 2, 3, 3], [5, 2, 1, 4])</code> debe devolver <code>[3, 4, 5]</code> .&#39;
testString: 'assert.sameMembers(sym([1, 2, 3, 3], [5, 2, 1, 4]), [3, 4, 5], "<code>sym([1, 2, 3, 3], [5, 2, 1, 4])</code> should return <code>[3, 4, 5]</code>.");'
- text: &#39; <code>sym([1, 2, 3, 3], [5, 2, 1, 4])</code> debe contener solo tres elementos.&#39;
testString: 'assert.equal(sym([1, 2, 3, 3], [5, 2, 1, 4]).length, 3, "<code>sym([1, 2, 3, 3], [5, 2, 1, 4])</code> should contain only three elements.");'
- text: &#39; <code>sym([1, 2, 3], [5, 2, 1, 4, 5])</code> debe devolver <code>[3, 4, 5]</code> .&#39;
testString: 'assert.sameMembers(sym([1, 2, 3], [5, 2, 1, 4, 5]), [3, 4, 5], "<code>sym([1, 2, 3], [5, 2, 1, 4, 5])</code> should return <code>[3, 4, 5]</code>.");'
- text: &#39; <code>sym([1, 2, 3], [5, 2, 1, 4, 5])</code> debe contener solo tres elementos.&#39;
testString: 'assert.equal(sym([1, 2, 3], [5, 2, 1, 4, 5]).length, 3, "<code>sym([1, 2, 3], [5, 2, 1, 4, 5])</code> should contain only three elements.");'
- text: &#39; <code>sym([1, 2, 5], [2, 3, 5], [3, 4, 5])</code> debe devolver <code>[1, 4, 5]</code> &#39;
testString: 'assert.sameMembers(sym([1, 2, 5], [2, 3, 5], [3, 4, 5]), [1, 4, 5], "<code>sym([1, 2, 5], [2, 3, 5], [3, 4, 5])</code> should return <code>[1, 4, 5]</code>");'
- text: &#39; <code>sym([1, 2, 5], [2, 3, 5], [3, 4, 5])</code> debe contener solo tres elementos.&#39;
testString: 'assert.equal(sym([1, 2, 5], [2, 3, 5], [3, 4, 5]).length, 3, "<code>sym([1, 2, 5], [2, 3, 5], [3, 4, 5])</code> should contain only three elements.");'
- text: &#39; <code>sym([1, 1, 2, 5], [2, 2, 3, 5], [3, 4, 5, 5])</code> debe devolver <code>[1, 4, 5]</code> .&#39;
testString: 'assert.sameMembers(sym([1, 1, 2, 5], [2, 2, 3, 5], [3, 4, 5, 5]), [1, 4, 5], "<code>sym([1, 1, 2, 5], [2, 2, 3, 5], [3, 4, 5, 5])</code> should return <code>[1, 4, 5]</code>.");'
- text: &#39; <code>sym([1, 1, 2, 5], [2, 2, 3, 5], [3, 4, 5, 5])</code> debe contener solo tres elementos.&#39;
testString: 'assert.equal(sym([1, 1, 2, 5], [2, 2, 3, 5], [3, 4, 5, 5]).length, 3, "<code>sym([1, 1, 2, 5], [2, 2, 3, 5], [3, 4, 5, 5])</code> should contain only three elements.");'
- text: &#39; <code>sym([3, 3, 3, 2, 5], [2, 1, 5, 7], [3, 4, 6, 6], [1, 2, 3])</code> debe devolver <code>[2, 3, 4, 6, 7]</code> .
testString: 'assert.sameMembers(sym([3, 3, 3, 2, 5], [2, 1, 5, 7], [3, 4, 6, 6], [1, 2, 3]), [2, 3, 4, 6, 7], "<code>sym([3, 3, 3, 2, 5], [2, 1, 5, 7], [3, 4, 6, 6], [1, 2, 3])</code> should return <code>[2, 3, 4, 6, 7]</code>.");'
- text: &#39; <code>sym([3, 3, 3, 2, 5], [2, 1, 5, 7], [3, 4, 6, 6], [1, 2, 3])</code> debe contener solo cinco elementos.&#39;
testString: 'assert.equal(sym([3, 3, 3, 2, 5], [2, 1, 5, 7], [3, 4, 6, 6], [1, 2, 3]).length, 5, "<code>sym([3, 3, 3, 2, 5], [2, 1, 5, 7], [3, 4, 6, 6], [1, 2, 3])</code> should contain only five elements.");'
- text: &#39; <code>sym([3, 3, 3, 2, 5], [2, 1, 5, 7], [3, 4, 6, 6], [1, 2, 3], [5, 3, 9, 8], [1])</code> debe devolver <code>[1, 2, 4, 5, 6, 7, 8, 9]</code> . &#39;
testString: 'assert.sameMembers(sym([3, 3, 3, 2, 5], [2, 1, 5, 7], [3, 4, 6, 6], [1, 2, 3], [5, 3, 9, 8], [1]), [1, 2, 4, 5, 6, 7, 8, 9], "<code>sym([3, 3, 3, 2, 5], [2, 1, 5, 7], [3, 4, 6, 6], [1, 2, 3], [5, 3, 9, 8], [1])</code> should return <code>[1, 2, 4, 5, 6, 7, 8, 9]</code>.");'
- text: &#39; <code>sym([3, 3, 3, 2, 5], [2, 1, 5, 7], [3, 4, 6, 6], [1, 2, 3], [5, 3, 9, 8], [1])</code> debe contener solo ocho elementos &#39;.
testString: 'assert.equal(sym([3, 3, 3, 2, 5], [2, 1, 5, 7], [3, 4, 6, 6], [1, 2, 3], [5, 3, 9, 8], [1]).length, 8, "<code>sym([3, 3, 3, 2, 5], [2, 1, 5, 7], [3, 4, 6, 6], [1, 2, 3], [5, 3, 9, 8], [1])</code> should contain only eight elements.");'
```
</section>
## Challenge Seed
<section id='challengeSeed'>
<div id='js-seed'>
```js
function sym(args) {
return args;
}
sym([1, 2, 3], [5, 2, 1, 4]);
```
</div>
</section>
## Solution
<section id='solution'>
```js
function sym() {
var arrays = [].slice.call(arguments);
return arrays.reduce(function (symDiff, arr) {
return symDiff.concat(arr).filter(function (val, idx, theArr) {
return theArr.indexOf(val) === idx
&& (symDiff.indexOf(val) === -1 || arr.indexOf(val) === -1);
});
});
}
sym([1, 2, 3], [5, 2, 1, 4]);
```
</section>

View File

@ -0,0 +1,77 @@
---
id: 8d5123c8c441eddfaeb5bdef
title: Implement Bubble Sort
localeTitle: Implementar Bubble Sort
challengeType: 1
---
## Description
<section id='description'>
Este es el primero de varios desafíos en la clasificación de algoritmos. Dada una matriz de elementos sin clasificar, queremos poder devolver una matriz ordenada. Veremos varios métodos diferentes para hacer esto y aprenderemos algunas compensaciones entre estos diferentes enfoques. Si bien la mayoría de los lenguajes modernos tienen métodos de clasificación incorporados para operaciones como esta, todavía es importante entender algunos de los enfoques básicos comunes y aprender cómo pueden implementarse.
Aquí veremos burbuja ordenada. El método de clasificación de burbujas comienza al principio de una matriz sin ordenar y &#39;burbujea&#39; valores sin ordenar hacia el final, iterando a través de la matriz hasta que esté completamente ordenada. Lo hace comparando elementos adyacentes e intercambiándolos si están fuera de orden. El método continúa en bucle a través de la matriz hasta que no se produzcan swaps en qué punto se clasifica la matriz.
Este método requiere múltiples iteraciones a través de la matriz y, en promedio, en el peor de los casos tiene una complejidad de tiempo cuadrática. Aunque simple, generalmente es poco práctico en la mayoría de las situaciones.
<strong>Instrucciones:</strong> Escriba una función <code>bubbleSort</code> que toma una matriz de enteros como entrada y devuelve una matriz de estos enteros en orden ordenado de menor a mayor.
<strong>Nota:</strong> <br> Estamos llamando a esta función desde detrás de la escena; La matriz de prueba que estamos utilizando está comentada en el editor. ¡Intente registrar la <code>array</code> para ver su algoritmo de clasificación en acción!
</section>
## Instructions
<section id='instructions'>
</section>
## Tests
<section id='tests'>
```yml
tests:
- text: <code>bubbleSort</code> es una función.
testString: 'assert(typeof bubbleSort == "function", "<code>bubbleSort</code> is a function.");'
- text: <code>bubbleSort</code> devuelve una matriz ordenada (de menor a mayor).
testString: 'assert(isSorted(bubbleSort([1,4,2,8,345,123,43,32,5643,63,123,43,2,55,1,234,92])), "<code>bubbleSort</code> returns a sorted array (least to greatest).");'
- text: <code>bubbleSort</code> devuelve una matriz que no se modifica, excepto para el orden.
testString: 'assert.sameMembers(bubbleSort([1,4,2,8,345,123,43,32,5643,63,123,43,2,55,1,234,92]), [1,4,2,8,345,123,43,32,5643,63,123,43,2,55,1,234,92], "<code>bubbleSort</code> returns an array that is unchanged except for order.");'
- text: <code>bubbleSort</code> no debe usar el método <code>.sort()</code> .
testString: 'assert.strictEqual(code.search(/\.sort\(/), -1, "<code>bubbleSort</code> should not use the built-in <code>.sort()</code> method.");'
```
</section>
## Challenge Seed
<section id='challengeSeed'>
<div id='js-seed'>
```js
function bubbleSort(array) {
// change code below this line
// change code above this line
return array;
}
// test array:
// [1, 4, 2, 8, 345, 123, 43, 32, 5643, 63, 123, 43, 2, 55, 1, 234, 92]
```
</div>
### After Test
<div id='js-teardown'>
```js
console.info('after the test');
```
</div>
</section>
## Solution
<section id='solution'>
```js
// solution required
```
</section>

View File

@ -0,0 +1,75 @@
---
id: 587d8259367417b2b2512c86
title: Implement Insertion Sort
localeTitle: Implementar orden de inserción
challengeType: 1
---
## Description
<section id='description'>
El siguiente método de clasificación que veremos es la ordenación por inserción. Este método funciona mediante la creación de una matriz ordenada al principio de la lista. Comienza la matriz ordenada con el primer elemento. Luego inspecciona el siguiente elemento y lo intercambia hacia atrás en la matriz ordenada hasta que esté en la posición ordenada. Continúa recorriendo la lista e intercambiando nuevos elementos hacia atrás en la parte ordenada hasta que llega al final. Este algoritmo tiene una complejidad de tiempo cuadrática en los casos promedio y en los peores.
<strong>Instrucciones:</strong> Escriba una función <code>insertionSort</code> que toma una matriz de enteros como entrada y devuelve una matriz de estos enteros en orden ordenado de menor a mayor.
<strong>Nota:</strong> <br> Estamos llamando a esta función desde detrás de la escena; La matriz de prueba que estamos utilizando está comentada en el editor. ¡Intente registrar la <code>array</code> para ver su algoritmo de clasificación en acción!
</section>
## Instructions
<section id='instructions'>
</section>
## Tests
<section id='tests'>
```yml
tests:
- text: <code>insertionSort</code> es una función.
testString: 'assert(typeof insertionSort == "function", "<code>insertionSort</code> is a function.");'
- text: <code>insertionSort</code> devuelve una matriz ordenada (menor a mayor).
testString: 'assert(isSorted(insertionSort([1,4,2,8,345,123,43,32,5643,63,123,43,2,55,1,234,92])), "<code>insertionSort</code> returns a sorted array (least to greatest).");'
- text: <code>insertionSort</code> devuelve una matriz que no se modifica, excepto para el orden.
testString: 'assert.sameMembers(insertionSort([1,4,2,8,345,123,43,32,5643,63,123,43,2,55,1,234,92]), [1,4,2,8,345,123,43,32,5643,63,123,43,2,55,1,234,92], "<code>insertionSort</code> returns an array that is unchanged except for order.");'
- text: <code>insertionSort</code> no debe usar el método <code>.sort()</code> .
testString: 'assert.strictEqual(code.search(/\.sort\(/), -1, "<code>insertionSort</code> should not use the built-in <code>.sort()</code> method.");'
```
</section>
## Challenge Seed
<section id='challengeSeed'>
<div id='js-seed'>
```js
function insertionSort(array) {
// change code below this line
// change code above this line
return array;
}
// test array:
// [1, 4, 2, 8, 345, 123, 43, 32, 5643, 63, 123, 43, 2, 55, 1, 234, 92]
```
</div>
### After Test
<div id='js-teardown'>
```js
console.info('after the test');
```
</div>
</section>
## Solution
<section id='solution'>
```js
// solution required
```
</section>

View File

@ -0,0 +1,79 @@
---
id: 587d825c367417b2b2512c8f
title: Implement Merge Sort
localeTitle: Implementar Merge Sort
challengeType: 1
---
## Description
<section id='description'>
Otro algoritmo de clasificación intermedio que es muy común es la clasificación por fusión. Al igual que la ordenación rápida, la ordenación combinada también usa una metodología recursiva de dividir y conquistar para ordenar una matriz. Aprovecha el hecho de que es relativamente fácil clasificar dos matrices siempre que cada una esté ordenada en primer lugar. Pero comenzaremos con solo una matriz como entrada, entonces, ¿cómo podemos obtener dos matrices ordenadas de eso? Bueno, podemos dividir recursivamente la entrada original en dos hasta que alcancemos el caso base de una matriz con un elemento. Una matriz de un solo elemento se ordena naturalmente, por lo que podemos comenzar a combinar. Esta combinación desenrollará las llamadas recursivas que dividen la matriz original, produciendo finalmente una matriz ordenada final de todos los elementos. Los pasos de la ordenación de fusión, entonces, son:
<strong>1)</strong> Divide recursivamente la matriz de entrada por la mitad hasta que se genere una sub-matriz con solo un elemento.
<strong>2)</strong> Fusione cada sub-matriz ordenada para producir la matriz final ordenada.
clasificación de mezcla es un método de clasificación eficiente, con una complejidad de tiempo de <i>O (nlog (n))</i> . Este algoritmo es popular porque es eficaz y relativamente fácil de implementar.
Como punto de partida, este será el último algoritmo de clasificación que cubrimos aquí. Sin embargo, más adelante en la sección sobre estructuras de datos de árbol, describiremos la ordenación de pilas, otro método de clasificación eficiente que requiere una pila binaria en su implementación.
<strong>Instrucciones:</strong> escriba una función <code>mergeSort</code> que tome una matriz de enteros como entrada y devuelva una matriz de estos enteros en orden ordenado de menor a mayor. Una buena manera de implementar esto es escribir una función, por ejemplo, <code>merge</code> , que es responsable de combinar dos matrices ordenadas, y otra función, por ejemplo <code>mergeSort</code> , que es responsable de la recursión que produce matrices de un solo elemento para alimentar la fusión. ¡Buena suerte!
<strong>Nota:</strong> <br> Estamos llamando a esta función desde detrás de la escena; La matriz de prueba que estamos utilizando está comentada en el editor. ¡Intente registrar la <code>array</code> para ver su algoritmo de clasificación en acción!
</section>
## Instructions
<section id='instructions'>
</section>
## Tests
<section id='tests'>
```yml
tests:
- text: <code>mergeSort</code> es una función.
testString: 'assert(typeof mergeSort == "function", "<code>mergeSort</code> is a function.");'
- text: <code>mergeSort</code> devuelve una matriz ordenada (menor a mayor).
testString: 'assert(isSorted(mergeSort([1,4,2,8,345,123,43,32,5643,63,123,43,2,55,1,234,92])), "<code>mergeSort</code> returns a sorted array (least to greatest).");'
- text: <code>mergeSort</code> devuelve una matriz que no se modifica, excepto para el orden.
testString: 'assert.sameMembers(mergeSort([1,4,2,8,345,123,43,32,5643,63,123,43,2,55,1,234,92]), [1,4,2,8,345,123,43,32,5643,63,123,43,2,55,1,234,92], "<code>mergeSort</code> returns an array that is unchanged except for order.");'
- text: <code>mergeSort</code> no debe usar el método <code>.sort()</code> .
testString: 'assert.strictEqual(code.search(/\.sort\(/), -1, "<code>mergeSort</code> should not use the built-in <code>.sort()</code> method.");'
```
</section>
## Challenge Seed
<section id='challengeSeed'>
<div id='js-seed'>
```js
function mergeSort(array) {
// change code below this line
// change code above this line
return array;
}
// test array:
// [1, 4, 2, 8, 345, 123, 43, 32, 5643, 63, 123, 43, 2, 55, 1, 234, 92]
```
</div>
### After Test
<div id='js-teardown'>
```js
console.info('after the test');
```
</div>
</section>
## Solution
<section id='solution'>
```js
// solution required
```
</section>

View File

@ -0,0 +1,76 @@
---
id: 587d825a367417b2b2512c89
title: Implement Quick Sort
localeTitle: Implementar ordenación rápida
challengeType: 1
---
## Description
<section id='description'>
Aquí pasaremos a un algoritmo de clasificación intermedio: ordenación rápida. La clasificación rápida es un método eficiente y recursivo de dividir y conquistar para clasificar una matriz. En este método, se elige un valor pivote en la matriz original. La matriz se divide en dos subgrupos de valores menores y mayores que el valor de pivote. Luego combinamos el resultado de llamar recursivamente el algoritmo de ordenamiento rápido en ambos subarreglos. Esto continúa hasta que se alcanza el caso base de una matriz vacía o de un solo elemento, que devolvemos. El desenrollamiento de las llamadas recursivas nos devuelve la matriz ordenada.
La clasificación rápida es un método de clasificación muy eficiente, que proporciona un rendimiento de <i>O (nlog (n))</i> en promedio. También es relativamente fácil de implementar. Estos atributos lo convierten en un método de clasificación popular y útil.
<strong>Instrucciones:</strong> escriba una función <code>quickSort</code> que tome una matriz de enteros como entrada y devuelva una matriz de estos enteros en orden ordenado de menor a mayor. Si bien la elección del valor de pivote es importante, cualquier pivote servirá para nuestros propósitos aquí. Por simplicidad, el primer o último elemento podría ser utilizado.
<strong>Nota:</strong> <br> Estamos llamando a esta función desde detrás de la escena; La matriz de prueba que estamos utilizando está comentada en el editor. ¡Intente registrar la <code>array</code> para ver su algoritmo de clasificación en acción!
</section>
## Instructions
<section id='instructions'>
</section>
## Tests
<section id='tests'>
```yml
tests:
- text: <code>quickSort</code> es una función.
testString: 'assert(typeof quickSort == "function", "<code>quickSort</code> is a function.");'
- text: <code>quickSort</code> devuelve una matriz ordenada (de menor a mayor).
testString: 'assert(isSorted(quickSort([1,4,2,8,345,123,43,32,5643,63,123,43,2,55,1,234,92])), "<code>quickSort</code> returns a sorted array (least to greatest).");'
- text: <code>quickSort</code> devuelve una matriz que no se modifica, excepto para el orden.
testString: 'assert.sameMembers(quickSort([1,4,2,8,345,123,43,32,5643,63,123,43,2,55,1,234,92]), [1,4,2,8,345,123,43,32,5643,63,123,43,2,55,1,234,92], "<code>quickSort</code> returns an array that is unchanged except for order.");'
- text: <code>quickSort</code> no debe usar el método <code>.sort()</code> .
testString: 'assert.strictEqual(code.search(/\.sort\(/), -1, "<code>quickSort</code> should not use the built-in <code>.sort()</code> method.");'
```
</section>
## Challenge Seed
<section id='challengeSeed'>
<div id='js-seed'>
```js
function quickSort(array) {
// change code below this line
// change code above this line
return array;
}
// test array:
// [1, 4, 2, 8, 345, 123, 43, 32, 5643, 63, 123, 43, 2, 55, 1, 234, 92]
```
</div>
### After Test
<div id='js-teardown'>
```js
console.info('after the test');
```
</div>
</section>
## Solution
<section id='solution'>
```js
// solution required
```
</section>

View File

@ -0,0 +1,75 @@
---
id: 587d8259367417b2b2512c85
title: Implement Selection Sort
localeTitle: Implementar Selección Ordenar
challengeType: 1
---
## Description
<section id='description'>
Aquí vamos a implementar la selección por selección. El ordenamiento por selección funciona seleccionando el valor mínimo en una lista e intercambiándolo con el primer valor en la lista. Luego comienza en la segunda posición, selecciona el valor más pequeño en la lista restante y lo intercambia con el segundo elemento. Continúa recorriendo la lista e intercambiando elementos hasta que llega al final de la lista. Ahora la lista está ordenada. El ordenamiento de selección tiene una complejidad de tiempo cuadrática en todos los casos.
<strong>Instrucciones</strong> : escriba una función <code>selectionSort</code> que toma una matriz de enteros como entrada y devuelve una matriz de estos enteros en orden ordenado de menor a mayor.
<strong>Nota:</strong> <br> Estamos llamando a esta función desde detrás de la escena; La matriz de prueba que estamos utilizando está comentada en el editor. ¡Intente registrar la <code>array</code> para ver su algoritmo de clasificación en acción!
</section>
## Instructions
<section id='instructions'>
</section>
## Tests
<section id='tests'>
```yml
tests:
- text: <code>selectionSort</code> es una función.
testString: 'assert(typeof selectionSort == "function", "<code>selectionSort</code> is a function.");'
- text: <code>selectionSort</code> devuelve una matriz ordenada (menor a mayor).
testString: 'assert(isSorted(selectionSort([1,4,2,8,345,123,43,32,5643,63,123,43,2,55,1,234,92])), "<code>selectionSort</code> returns a sorted array (least to greatest).");'
- text: <code>selectionSort</code> devuelve una matriz que no se modifica, excepto para el orden.
testString: 'assert.sameMembers(selectionSort([1,4,2,8,345,123,43,32,5643,63,123,43,2,55,1,234,92]), [1,4,2,8,345,123,43,32,5643,63,123,43,2,55,1,234,92], "<code>selectionSort</code> returns an array that is unchanged except for order.");'
- text: <code>selectionSort</code> no debe usar el método <code>.sort()</code> .
testString: 'assert.strictEqual(code.search(/\.sort\(/), -1, "<code>selectionSort</code> should not use the built-in <code>.sort()</code> method.");'
```
</section>
## Challenge Seed
<section id='challengeSeed'>
<div id='js-seed'>
```js
function selectionSort(array) {
// change code below this line
// change code above this line
return array;
}
// test array:
// [1, 4, 2, 8, 345, 123, 43, 32, 5643, 63, 123, 43, 2, 55, 1, 234, 92]
```
</div>
### After Test
<div id='js-teardown'>
```js
console.info('after the test');
```
</div>
</section>
## Solution
<section id='solution'>
```js
// solution required
```
</section>

View File

@ -0,0 +1,122 @@
---
id: a56138aff60341a09ed6c480
title: Inventory Update
localeTitle: Actualización de inventario
challengeType: 5
---
## Description
<section id='description'>
Compare y actualice el inventario almacenado en una matriz 2D con una segunda matriz 2D de una entrega nueva. Actualice las cantidades de artículos de inventario existentes actuales (en <code>arr1</code> ). Si no se puede encontrar un artículo, agregue el nuevo artículo y la cantidad en la matriz de inventario. La matriz de inventario devuelta debe estar ordenada alfabéticamente por artículo.
Recuerda usar <a href='http://forum.freecodecamp.org/t/how-to-get-help-when-you-are-stuck/19514' target='_blank'>Read-Search-Ask</a> si te atascas. Trate de emparejar el programa. Escribe tu propio código.
</section>
## Instructions
<section id='instructions'>
</section>
## Tests
<section id='tests'>
```yml
tests:
- text: La función <code>updateInventory</code> debería devolver una matriz.
testString: '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"]]), "The function <code>updateInventory</code> should return an array.");'
- text: &#39; <code>updateInventory([[21, &quot;Bowling Ball&quot;], [2, &quot;Dirty Sock&quot;], [1, &quot;Hair Pin&quot;], [5, &quot;Microphone&quot;]], [[2, &quot;Hair Pin&quot;], [3, &quot;Half-Eaten Apple&quot;], [67, &quot;Bowling Ball&quot;], [7, &quot;Toothpaste&quot;]])</code> debe devolver una matriz con una longitud de 6. &#39;
testString: '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"]]).length, 6, "<code>updateInventory([[21, "Bowling Ball"], [2, "Dirty Sock"], [1, "Hair Pin"], [5, "Microphone"]], [[2, "Hair Pin"], [3, "Half-Eaten Apple"], [67, "Bowling Ball"], [7, "Toothpaste"]])</code> should return an array with a length of 6.");'
- text: &#39; <code>updateInventory([[21, &quot;Bowling Ball&quot;], [2, &quot;Dirty Sock&quot;], [1, &quot;Hair Pin&quot;], [5, &quot;Microphone&quot;]], [[2, &quot;Hair Pin&quot;], [3, &quot;Half-Eaten Apple&quot;], [67, &quot;Bowling Ball&quot;], [7, &quot;Toothpaste&quot;]])</code> debe devolver <code>[[88, &quot;Bowling Ball&quot;], [2, &quot;Dirty Sock&quot;], [3, &quot;Hair Pin&quot;], [3, &quot;Half-Eaten Apple&quot;], [5, &quot;Microphone&quot;], [7, &quot;Toothpaste&quot;]]</code> . &#39;
testString: 'assert.deepEqual(updateInventory([[21, "Bowling Ball"], [2, "Dirty Sock"], [1, "Hair Pin"], [5, "Microphone"]], [[2, "Hair Pin"], [3, "Half-Eaten Apple"], [67, "Bowling Ball"], [7, "Toothpaste"]]), [[88, "Bowling Ball"], [2, "Dirty Sock"], [3, "Hair Pin"], [3, "Half-Eaten Apple"], [5, "Microphone"], [7, "Toothpaste"]], "<code>updateInventory([[21, "Bowling Ball"], [2, "Dirty Sock"], [1, "Hair Pin"], [5, "Microphone"]], [[2, "Hair Pin"], [3, "Half-Eaten Apple"], [67, "Bowling Ball"], [7, "Toothpaste"]])</code> should return <code>[[88, "Bowling Ball"], [2, "Dirty Sock"], [3, "Hair Pin"], [3, "Half-Eaten Apple"], [5, "Microphone"], [7, "Toothpaste"]]</code>.");'
- text: &#39; <code>updateInventory([[21, &quot;Bowling Ball&quot;], [2, &quot;Dirty Sock&quot;], [1, &quot;Hair Pin&quot;], [5, &quot;Microphone&quot;]], [])</code> debe devolver <code>[[21, &quot;Bowling Ball&quot;], [2, &quot;Dirty Sock&quot;], [1, &quot;Hair Pin&quot;], [5, &quot;Microphone&quot;]]</code> . &#39;
testString: 'assert.deepEqual(updateInventory([[21, "Bowling Ball"], [2, "Dirty Sock"], [1, "Hair Pin"], [5, "Microphone"]], []), [[21, "Bowling Ball"], [2, "Dirty Sock"], [1, "Hair Pin"], [5, "Microphone"]], "<code>updateInventory([[21, "Bowling Ball"], [2, "Dirty Sock"], [1, "Hair Pin"], [5, "Microphone"]], [])</code> should return <code>[[21, "Bowling Ball"], [2, "Dirty Sock"], [1, "Hair Pin"], [5, "Microphone"]]</code>.");'
- text: &#39; <code>updateInventory([], [[2, &quot;Hair Pin&quot;], [3, &quot;Half-Eaten Apple&quot;], [67, &quot;Bowling Ball&quot;], [7, &quot;Toothpaste&quot;]])</code> debe devolver <code>[[67, &quot;Bowling Ball&quot;], [2, &quot;Hair Pin&quot;], [3, &quot;Half-Eaten Apple&quot;], [7, &quot;Toothpaste&quot;]]</code> . &#39;
testString: 'assert.deepEqual(updateInventory([], [[2, "Hair Pin"], [3, "Half-Eaten Apple"], [67, "Bowling Ball"], [7, "Toothpaste"]]), [[67, "Bowling Ball"], [2, "Hair Pin"], [3, "Half-Eaten Apple"], [7, "Toothpaste"]], "<code>updateInventory([], [[2, "Hair Pin"], [3, "Half-Eaten Apple"], [67, "Bowling Ball"], [7, "Toothpaste"]])</code> should return <code>[[67, "Bowling Ball"], [2, "Hair Pin"], [3, "Half-Eaten Apple"], [7, "Toothpaste"]]</code>.");'
- text: &#39; <code>updateInventory([[0, &quot;Bowling Ball&quot;], [0, &quot;Dirty Sock&quot;], [0, &quot;Hair Pin&quot;], [0, &quot;Microphone&quot;]], [[1, &quot;Hair Pin&quot;], [1, &quot;Half-Eaten Apple&quot;], [1, &quot;Bowling Ball&quot;], [1, &quot;Toothpaste&quot;]])</code> debe devolver <code>[[1, &quot;Bowling Ball&quot;], [0, &quot;Dirty Sock&quot;], [1, &quot;Hair Pin&quot;], [1, &quot;Half-Eaten Apple&quot;], [0, &quot;Microphone&quot;], [1, &quot;Toothpaste&quot;]]</code> . &#39;
testString: '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"]]), [[1, "Bowling Ball"], [0, "Dirty Sock"], [1, "Hair Pin"], [1, "Half-Eaten Apple"], [0, "Microphone"], [1, "Toothpaste"]], "<code>updateInventory([[0, "Bowling Ball"], [0, "Dirty Sock"], [0, "Hair Pin"], [0, "Microphone"]], [[1, "Hair Pin"], [1, "Half-Eaten Apple"], [1, "Bowling Ball"], [1, "Toothpaste"]])</code> should return <code>[[1, "Bowling Ball"], [0, "Dirty Sock"], [1, "Hair Pin"], [1, "Half-Eaten Apple"], [0, "Microphone"], [1, "Toothpaste"]]</code>.");'
```
</section>
## Challenge Seed
<section id='challengeSeed'>
<div id='js-seed'>
```js
function updateInventory(arr1, arr2) {
// All inventory must be accounted for or you're fired!
return arr1;
}
// Example inventory lists
var curInv = [
[21, "Bowling Ball"],
[2, "Dirty Sock"],
[1, "Hair Pin"],
[5, "Microphone"]
];
var newInv = [
[2, "Hair Pin"],
[3, "Half-Eaten Apple"],
[67, "Bowling Ball"],
[7, "Toothpaste"]
];
updateInventory(curInv, newInv);
```
</div>
</section>
## Solution
<section id='solution'>
```js
function updateInventory(arr1, arr2) {
arr2.forEach(function(item) {
createOrUpdate(arr1, item);
});
// All inventory must be accounted for or you're fired!
return arr1;
}
function createOrUpdate(arr1, item) {
var index = -1;
while (++index < arr1.length) {
if (arr1[index][1] === item[1]) {
arr1[index][0] += item[0];
return;
}
if (arr1[index][1] > item[1]) {
break;
}
}
arr1.splice(index, 0, item);
}
// Example inventory lists
var curInv = [
[21, 'Bowling Ball'],
[2, 'Dirty Sock'],
[1, 'Hair Pin'],
[5, 'Microphone']
];
var newInv = [
[2, 'Hair Pin'],
[3, 'Half-Eaten Apple'],
[67, 'Bowling Ball'],
[7, 'Toothpaste']
];
updateInventory(curInv, newInv);
```
</section>

View File

@ -0,0 +1,111 @@
---
id: a7bf700cd123b9a54eef01d5
title: No Repeats Please
localeTitle: No se repite por favor
challengeType: 5
---
## Description
<section id='description'>
Devuelve el número de permutaciones totales de la cadena proporcionada que no tienen letras consecutivas repetidas. Supongamos que todos los caracteres de la cadena proporcionada son únicos.
Por ejemplo, <code>aab</code> debería devolver 2 porque tiene 6 permutaciones totales ( <code>aab</code> , <code>aab</code> , <code>aba</code> , <code>aba</code> , <code>baa</code> , <code>baa</code> ), pero solo 2 de ellas ( <code>aba</code> y <code>aba</code> ) no tienen la misma letra (en este caso, <code>a</code> ) repitiendo.
Recuerda usar <a href='http://forum.freecodecamp.org/t/how-to-get-help-when-you-are-stuck/19514' target='_blank'>Read-Search-Ask</a> si te atascas. Trate de emparejar el programa. Escribe tu propio código.
</section>
## Instructions
<section id='instructions'>
</section>
## Tests
<section id='tests'>
```yml
tests:
- text: <code>permAlone(&quot;aab&quot;)</code> debe devolver un número.
testString: 'assert.isNumber(permAlone("aab"), "<code>permAlone("aab")</code> should return a number.");'
- text: <code>permAlone(&quot;aab&quot;)</code> debe devolver 2.
testString: 'assert.strictEqual(permAlone("aab"), 2, "<code>permAlone("aab")</code> should return 2.");'
- text: <code>permAlone(&quot;aaa&quot;)</code> debe devolver 0.
testString: 'assert.strictEqual(permAlone("aaa"), 0, "<code>permAlone("aaa")</code> should return 0.");'
- text: <code>permAlone(&quot;aabb&quot;)</code> debe devolver 8.
testString: 'assert.strictEqual(permAlone("aabb"), 8, "<code>permAlone("aabb")</code> should return 8.");'
- text: <code>permAlone(&quot;abcdefa&quot;)</code> debe devolver 3600.
testString: 'assert.strictEqual(permAlone("abcdefa"), 3600, "<code>permAlone("abcdefa")</code> should return 3600.");'
- text: <code>permAlone(&quot;abfdefa&quot;)</code> debe devolver 2640.
testString: 'assert.strictEqual(permAlone("abfdefa"), 2640, "<code>permAlone("abfdefa")</code> should return 2640.");'
- text: <code>permAlone(&quot;zzzzzzzz&quot;)</code> debe devolver 0.
testString: 'assert.strictEqual(permAlone("zzzzzzzz"), 0, "<code>permAlone("zzzzzzzz")</code> should return 0.");'
- text: <code>permAlone(&quot;a&quot;)</code> debe devolver 1.
testString: 'assert.strictEqual(permAlone("a"), 1, "<code>permAlone("a")</code> should return 1.");'
- text: <code>permAlone(&quot;aaab&quot;)</code> debe devolver 0.
testString: 'assert.strictEqual(permAlone("aaab"), 0, "<code>permAlone("aaab")</code> should return 0.");'
- text: <code>permAlone(&quot;aaabb&quot;)</code> debe devolver 12.
testString: 'assert.strictEqual(permAlone("aaabb"), 12, "<code>permAlone("aaabb")</code> should return 12.");'
```
</section>
## Challenge Seed
<section id='challengeSeed'>
<div id='js-seed'>
```js
function permAlone(str) {
return str;
}
permAlone('aab');
```
</div>
</section>
## Solution
<section id='solution'>
```js
function permAlone(str) {
return permutor(str).filter(function(perm) {
return !perm.match(/(.)\1/g);
}).length;
}
function permutor(str) {
// http://staff.roguecc.edu/JMiller/JavaScript/permute.html
//permArr: Global array which holds the list of permutations
//usedChars: Global utility array which holds a list of "currently-in-use" characters
var permArr = [], usedChars = [];
function permute(input) {
//convert input into a char array (one element for each character)
var i, ch, chars = input.split("");
for (i = 0; i < chars.length; i++) {
//get and remove character at index "i" from char array
ch = chars.splice(i, 1);
//add removed character to the end of used characters
usedChars.push(ch);
//when there are no more characters left in char array to add, add used chars to list of permutations
if (chars.length === 0) permArr[permArr.length] = usedChars.join("");
//send characters (minus the removed one from above) from char array to be permuted
permute(chars.join(""));
//add removed character back into char array in original position
chars.splice(i, 0, ch);
//remove the last character used off the end of used characters array
usedChars.pop();
}
}
permute(str);
return permArr;
}
permAlone('aab');
```
</section>

View File

@ -0,0 +1,89 @@
---
id: a3f503de51cfab748ff001aa
title: Pairwise
localeTitle: Por pares
challengeType: 5
---
## Description
<section id='description'>
Dado una matriz <code>arr</code> , encuentre pares de elementos cuya suma sea igual al segundo argumento <code>arg</code> y devuelva la suma de sus índices.
Puede usar varios pares que tengan los mismos elementos numéricos pero diferentes índices. Cada par debe usar los índices disponibles más bajos posibles. Una vez que se ha utilizado un elemento, no puede reutilizarse para emparejarse con otro elemento. Por ejemplo, por <code>pairwise([1, 1, 2], 3)</code> crea un par <code>[2, 1]</code> usando el 1 en el índice 0 en lugar del 1 en el índice 1, porque 0 + 2 &lt;1 + 2.
Por ejemplo, por <code>pairwise([7, 9, 11, 13, 15], 20)</code> devuelve <code>6</code> . Los pares que suman 20 son <code>[7, 13]</code> y <code>[9, 11]</code> . Luego podemos escribir la matriz con sus índices y valores.
<table class="table"><tr><th> <strong>Índice</strong> </th><th> 0 </th><th> 1 </th><th> 2 </th><th> 3 </th><th> 4 </th></tr><tr><td> Valor </td><td> 7 </td><td> 9 </td><td> 11 </td><td> 13 </td><td> 15 </td></tr></table>
A continuación tomaremos sus índices correspondientes y los añadiremos.
7 + 13 = 20 → Índices 0 + 3 = 3 <br> 9 + 11 = 20 → Índices 1 + 2 = 3 <br> 3 + 3 = 6 → Volver <code>6</code>
Recuerda usar <a href='http://forum.freecodecamp.org/t/how-to-get-help-when-you-are-stuck/19514' target='_blank'>Read-Search-Ask</a> si te atascas. Trate de emparejar el programa. Escribe tu propio código.
</section>
## Instructions
<section id='instructions'>
</section>
## Tests
<section id='tests'>
```yml
tests:
- text: &#39; <code>pairwise([1, 4, 2, 3, 0, 5], 7)</code> debe devolver 11.&#39;
testString: 'assert.deepEqual(pairwise([1, 4, 2, 3, 0, 5], 7), 11, "<code>pairwise([1, 4, 2, 3, 0, 5], 7)</code> should return 11.");'
- text: &#39; <code>pairwise([1, 3, 2, 4], 4)</code> debe devolver 1.&#39;
testString: 'assert.deepEqual(pairwise([1, 3, 2, 4], 4), 1, "<code>pairwise([1, 3, 2, 4], 4)</code> should return 1.");'
- text: &#39; <code>pairwise([1, 1, 1], 2)</code> debe devolver 1.&#39;
testString: 'assert.deepEqual(pairwise([1, 1, 1], 2), 1, "<code>pairwise([1, 1, 1], 2)</code> should return 1.");'
- text: &#39; <code>pairwise([0, 0, 0, 0, 1, 1], 1)</code> debe devolver 10.&#39;
testString: 'assert.deepEqual(pairwise([0, 0, 0, 0, 1, 1], 1), 10, "<code>pairwise([0, 0, 0, 0, 1, 1], 1)</code> should return 10.");'
- text: &#39; <code>pairwise([], 100)</code> debe devolver 0.&#39;
testString: 'assert.deepEqual(pairwise([], 100), 0, "<code>pairwise([], 100)</code> should return 0.");'
```
</section>
## Challenge Seed
<section id='challengeSeed'>
<div id='js-seed'>
```js
function pairwise(arr, arg) {
return arg;
}
pairwise([1,4,2,3,0,5], 7);
```
</div>
</section>
## Solution
<section id='solution'>
```js
function pairwise(arr, arg) {
var sum = 0;
arr.forEach(function(e, i, a) {
if (e != null) {
var diff = arg-e;
a[i] = null;
var dix = a.indexOf(diff);
if (dix !== -1) {
sum += dix;
sum += i;
a[dix] = null;
}
}
});
return sum;
}
pairwise([1,4,2,3,0,5], 7);
```
</section>