Skip to content

Commit 3e360ee

Browse files
committed
translated task 1
1 parent ab13c34 commit 3e360ee

File tree

2 files changed

+17
-17
lines changed

2 files changed

+17
-17
lines changed

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+
Soluția folosind un loop:
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+
Soluția folosind recursivitatea:
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+
Soluția folosind formula: `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.S. Firește, formula este cea mai rapidă soluție. Ea folosește doar 3 operații pentru orice număr `n`. Matematica ajută!
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+
Varianta cu bucle este a doua în ceea ce privește viteza. Atât în varianta recursivă cât și în varianta loop adunăm aceleași numere. Dar recursivitatea implică apeluri nested și gestionare de execution stack. Și asta necesită resurse, deci este mai lent.
3939

40-
P.P.S. Some engines support the "tail call" optimization: if a recursive call is the very last one in the function, with no other calculations performed, 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. 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.S. Unele motoare suportă optimizarea "tail call": dacă un apel recursiv este chiar ultimul din funcție, fără alte calcule efectuate, atunci funcția exterioară nu va trebui să reia execuția, astfel încât motorul nu trebuie să își amintească contextul de execuție. Asta elimină povara asupra memoriei. Dar dacă motorul JavaScript nu acceptă optimizarea tail call (majoritatea nu o fac), va apărea o eroare: maximum stack size exceeded, deoarece există de obicei o limitare a dimensiunii totale din stack.

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+
# Însumați toate numerele până la cel dat
66

7-
Write a function `sumTo(n)` that calculates the sum of numbers `1 + 2 + ... + n`.
7+
Scrieți o funcție `sumTo(n)` care calculează suma numerelor `1 + 2 + ... + n`.
88

9-
For instance:
9+
De exemplu:
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+
Faceți 3 variante de soluție:
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. Folosind un for loop.
23+
2. Folosind o recursiune, cauza `sumTo(n) = n + sumTo(n-1)` pentru `n > 1`.
24+
3. Folosind formula de [progresie aritmetică](https://en.wikipedia.org/wiki/Arithmetic_progression).
2525

26-
An example of the result:
26+
Un exemplu de rezultat:
2727

2828
```js
29-
function sumTo(n) { /*... your code ... */ }
29+
function sumTo(n) { /*... codul tău ... */ }
3030

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

34-
P.S. Which solution variant is the fastest? The slowest? Why?
34+
P.S. Care variantă de soluție este cea mai rapidă? Cea mai lentă? De ce?
3535

36-
P.P.S. Can we use recursion to count `sumTo(100000)`?
36+
P.P.S. Putem folosi recursivitatea pentru a număra `sumTo(100000)`?

0 commit comments

Comments
 (0)