Skip to content

Commit 99b380a

Browse files
committed
translated until line 71
1 parent ef4b3ea commit 99b380a

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

1-js/06-advanced-functions/01-recursion/article.md

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,25 +10,25 @@ Recursiunea este un tipar de programare care este util în situațiile în care
1010

1111
Atunci când o funcție îndeplinește o sarcină, în acest proces poate apela multe alte funcții. Un caz parțial este atunci când o funcție se apelează pe sine *însăși*. Acest lucru se numește *recursiune*.
1212

13-
## Two ways of thinking
13+
## Două moduri de a gândi
1414

15-
For something simple to start with -- let's write a function `pow(x, n)` that raises `x` to a natural power of `n`. In other words, multiplies `x` by itself `n` times.
15+
Pentru a începe cu ceva simplu -- să scriem o funcție `pow(x, n)` care ridică `x` la o putere naturală a lui `n`. Cu alte cuvinte, înmulțește `x` cu el însuși de `n` ori.
1616

1717
```js
1818
pow(2, 2) = 4
1919
pow(2, 3) = 8
2020
pow(2, 4) = 16
2121
```
2222

23-
There are two ways to implement it.
23+
Există două moduri de a o implementa.
2424

25-
1. Iterative thinking: the `for` loop:
25+
1. Gândire iterativă: `for` loop:
2626

2727
```js run
2828
function pow(x, n) {
2929
let result = 1;
3030

31-
// multiply result by x n times in the loop
31+
// înmulțește rezultatul cu x de n ori în loop
3232
for (let i = 0; i < n; i++) {
3333
result *= x;
3434
}
@@ -39,7 +39,7 @@ There are two ways to implement it.
3939
alert( pow(2, 3) ); // 8
4040
```
4141

42-
2. Recursive thinking: simplify the task and call self:
42+
2. Gândire recursivă: simplificând sarcină și apelânduse pe sine:
4343

4444
```js run
4545
function pow(x, n) {
@@ -53,9 +53,9 @@ There are two ways to implement it.
5353
alert( pow(2, 3) ); // 8
5454
```
5555

56-
Please note how the recursive variant is fundamentally different.
56+
Vă rugăm să observați că varianta recursivă este fundamental diferită.
5757

58-
When `pow(x, n)` is called, the execution splits into two branches:
58+
Atunci când `pow(x, n)` este apelată, execuția se împarte în două ramuri:
5959

6060
```js
6161
if n==1 = x
@@ -65,10 +65,10 @@ pow(x, n) =
6565
else = x * pow(x, n - 1)
6666
```
6767

68-
1. If `n == 1`, then everything is trivial. It is called *the base* of recursion, because it immediately produces the obvious result: `pow(x, 1)` equals `x`.
69-
2. Otherwise, we can represent `pow(x, n)` as `x * pow(x, n - 1)`. In maths, one would write <code>x<sup>n</sup> = x * x<sup>n-1</sup></code>. This is called *a recursive step*: we transform the task into a simpler action (multiplication by `x`) and a simpler call of the same task (`pow` with lower `n`). Next steps simplify it further and further until `n` reaches `1`.
68+
1. Dacă `n == 1`, atunci totul este trivial. Se numește *baza* recursiunii, pentru că produce imediat rezultatul cel evident: `pow(x, 1)` egal cu `x`.
69+
2. În caz contrar, putem reprezenta `pow(x, n)` ca și `x * pow(x, n - 1)`. În matematică, am putea scrie <code>x<sup>n</sup> = x * x<sup>n-1</sup></code>. Acesta se numește *un pas recursiv*: transformăm sarcina într-o acțiune mai simplă (multiplicare cu `x`) și un apel mai simplu al aceleiași sarcini (`pow` cu `n` mai mic). Următorii pași o simplifică mai mult și mai mult până când `n` ajunge la `1`.
7070

71-
We can also say that `pow` *recursively calls itself* till `n == 1`.
71+
Putem de asemenea spune că `pow` *se apelează recursiv pe sine* până când `n == 1`.
7272

7373
![recursive diagram of pow](recursion-pow.svg)
7474

0 commit comments

Comments
 (0)