Skip to content

Commit 102399a

Browse files
authored
Merge pull request #400 from Arnau-Ninerola/master
Transltion of sum to task and solution
2 parents b858434 + d6c9472 commit 102399a

2 files changed

Lines changed: 17 additions & 17 deletions

File tree

1-js/06-advanced-functions/01-recursion/01-sum-to/solution.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
The solution using a loop:
1+
La solución usando un bucle:
22

33
```js run
44
function sumTo(n) {
@@ -12,7 +12,7 @@ function sumTo(n) {
1212
alert( sumTo(100) );
1313
```
1414

15-
The solution using recursion:
15+
La solución usando recursividad:
1616

1717
```js run
1818
function sumTo(n) {
@@ -23,7 +23,7 @@ function sumTo(n) {
2323
alert( sumTo(100) );
2424
```
2525

26-
The solution using the formula: `sumTo(n) = n*(n+1)/2`:
26+
La solución usando la fórmula: `sumTo(n) = n*(n+1)/2`:
2727

2828
```js run
2929
function sumTo(n) {
@@ -33,8 +33,8 @@ function sumTo(n) {
3333
alert( sumTo(100) );
3434
```
3535

36-
P.S. Naturally, the formula is the fastest solution. It uses only 3 operations for any number `n`. The math helps!
36+
P.D. Naturalmente, la fórmula es la solución más rápida. Utiliza solo 3 operaciones para cualquier número `n` ¡Las matemáticas ayudan!
3737

38-
The loop variant is the second in terms of speed. In both the recursive and the loop variant we sum the same numbers. But the recursion involves nested calls and execution stack management. That also takes resources, so it's slower.
38+
La variación con el bucle es la segunda en términos de velocidad. Tanto en la variante recursiva como en el bucle sumamos los mismos números. Pero la recursión implica llamadas anidadas y gestión de la pila de ejecución. Eso también requiere recursos, por lo que es más lento.
3939

40-
P.P.S. Some engines support the "tail call" optimization: if a recursive call is the very last one in the function (like in `sumTo` above), then the outer function will not need to resume the execution, so the engine doesn't need to remember its execution context. That removes the burden on memory, so counting `sumTo(100000)` becomes possible. But if the JavaScript engine does not support tail call optimization (most of them don't), there will be an error: maximum stack size exceeded, because there's usually a limitation on the total stack size.
40+
P.P.D. Algunos motores admiten la optimización de "tail call": si una llamada recursiva es la última en la función (como en la función anterior `sumTo`), entonces la función externa no necesitará reanudar la ejecución, por lo que el motor no necesita recordar su contexto de ejecución. Eso elimina la carga en la memoria, así que contar `sumTo(100000)` resulta posible. Pero si el motor de JavaScript no soporta la optimización "tail call" (la mayoría no lo hacen), entonces habrá un error: exceso del tamaño máximo de la pila, porque generalmente hay una limitación en el tamaño total de la pila.

1-js/06-advanced-functions/01-recursion/01-sum-to/task.md

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

33
---
44

5-
# Sum all numbers till the given one
5+
# Suma todos los números hasta el elegido
66

7-
Write a function `sumTo(n)` that calculates the sum of numbers `1 + 2 + ... + n`.
7+
Escribe una función `sumTo(n)` que calcule la suma de los números `1 + 2 + ... + n`.
88

9-
For instance:
9+
Por ejemplo:
1010

1111
```js no-beautify
1212
sumTo(1) = 1
@@ -17,20 +17,20 @@ sumTo(4) = 4 + 3 + 2 + 1 = 10
1717
sumTo(100) = 100 + 99 + ... + 2 + 1 = 5050
1818
```
1919

20-
Make 3 solution variants:
20+
Escribe 3 soluciones diferentes:
2121

22-
1. Using a for loop.
23-
2. Using a recursion, cause `sumTo(n) = n + sumTo(n-1)` for `n > 1`.
24-
3. Using the [arithmetic progression](https://en.wikipedia.org/wiki/Arithmetic_progression) formula.
22+
1. Utilizando un bucle.
23+
2. Usando la recursividad, causa `sumTo(n) = n + sumTo(n-1)` para `n > 1`.
24+
3. Utilizando la fórmula de [progresión aritmética](https://es.wikipedia.org/wiki/Progresi%C3%B3n_aritm%C3%A9tica).
2525

26-
An example of the result:
26+
Un ejemplo del resultado:
2727

2828
```js
29-
function sumTo(n) { /*... your code ... */ }
29+
function sumTo(n) { /*... tu código ... */ }
3030

3131
alert( sumTo(100) ); // 5050
3232
```
3333

34-
P.S. Which solution variant is the fastest? The slowest? Why?
34+
P.D. ¿Qué variante de la solución es la más rápida? ¿Y la más lenta? ¿Por qué?
3535

36-
P.P.S. Can we use recursion to count `sumTo(100000)`?
36+
P.P.D. ¿Podemos usar la recursión para contar `sumTo(100000)`?

0 commit comments

Comments
 (0)