Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions 1-js/06-advanced-functions/01-recursion/01-sum-to/solution.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
The solution using a loop:
La solución usando un bucle:

```js run
function sumTo(n) {
Expand All @@ -12,7 +12,7 @@ function sumTo(n) {
alert( sumTo(100) );
```

The solution using recursion:
La solución usando recursividad:

```js run
function sumTo(n) {
Expand All @@ -23,7 +23,7 @@ function sumTo(n) {
alert( sumTo(100) );
```

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

```js run
function sumTo(n) {
Expand All @@ -33,8 +33,8 @@ function sumTo(n) {
alert( sumTo(100) );
```

P.S. Naturally, the formula is the fastest solution. It uses only 3 operations for any number `n`. The math helps!
P.S. 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!
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

español "posdata"

Suggested change
P.S. 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!
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!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Lo estuve investigando y he visto que posdata (o postdata) pueden ser intercambiados por post scriptum (P.S.) y quería dejarlo así, ya que el P.S.S. no tiene traducción al español así resulta menos confuso creo. Pero lo cambio a posdata si quieres.

De wikipedia:

Es intercambiable con post scriptum (P. S.), "después de lo escrito". Siendo en la actualidad costumbre de fechar las cartas en el encabezado, y sin hablar de incorrección, podría ser preferible el término post scriptum (P. S.) para ese fin, al menos en ese contexto.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

👍

Debi poner post posdata si quería "corregirlo"

Igual, no uso la wiki como referencia de español, pero sí fundeu, acá aceptan también P.S.

https://www.fundeu.es/recomendacion/posdata-postdata-como-se-escribe/

"easy points" podes revisar el repo ya que habrá otross casos de P.P.D. jaja

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Como tú veas, si quieres lo cambio a P.D. ya que es lo más habitual. Más delante puedo revisar lo de P.P.D. y cambiarlos todos los que encuentre en un solo PR pero me voy a centrar en traducciones completas por ahora.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Ya está aprobado, PS es correcto, lo deje sin resolver por si otro lo lee.
cambiar los PDD que hubiera por PSS es un poco broma (por lo de easy points) hay otras prioridades pero si lo haces, apruebo, es más perfectón .


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.
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.

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.
P.P.S. 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.
Comment thread
Niroa95 marked this conversation as resolved.
Outdated
22 changes: 11 additions & 11 deletions 1-js/06-advanced-functions/01-recursion/01-sum-to/task.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ importance: 5

---

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

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

For instance:
Por ejemplo:

```js no-beautify
sumTo(1) = 1
Expand All @@ -17,20 +17,20 @@ sumTo(4) = 4 + 3 + 2 + 1 = 10
sumTo(100) = 100 + 99 + ... + 2 + 1 = 5050
```

Make 3 solution variants:
Escribe 3 soluciones diferentes:

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

An example of the result:
Un ejemplo del resultado:

```js
function sumTo(n) { /*... your code ... */ }
function sumTo(n) { /*... tu código ... */ }

alert( sumTo(100) ); // 5050
```

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

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