You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: 1-js/06-advanced-functions/01-recursion/article.md
+11-11Lines changed: 11 additions & 11 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -10,25 +10,25 @@ Recursiunea este un tipar de programare care este util în situațiile în care
10
10
11
11
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*.
12
12
13
-
## Two ways of thinking
13
+
## Două moduri de a gândi
14
14
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.
16
16
17
17
```js
18
18
pow(2, 2) =4
19
19
pow(2, 3) =8
20
20
pow(2, 4) =16
21
21
```
22
22
23
-
There are two ways to implement it.
23
+
Există două moduri de a o implementa.
24
24
25
-
1.Iterative thinking: the`for` loop:
25
+
1.Gândire iterativă:`for` loop:
26
26
27
27
```js run
28
28
functionpow(x, n) {
29
29
let result =1;
30
30
31
-
//multiply result by x n times in the loop
31
+
//înmulțește rezultatul cu x de n ori în loop
32
32
for (let i =0; i < n; i++) {
33
33
result *= x;
34
34
}
@@ -39,7 +39,7 @@ There are two ways to implement it.
39
39
alert( pow(2, 3) ); // 8
40
40
```
41
41
42
-
2.Recursive thinking: simplify the task and call self:
42
+
2.Gândire recursivă: simplificând sarcină și apelânduse pe sine:
43
43
44
44
```js run
45
45
function pow(x, n) {
@@ -53,9 +53,9 @@ There are two ways to implement it.
53
53
alert( pow(2, 3) ); // 8
54
54
```
55
55
56
-
Please note how the recursive variant is fundamentally different.
56
+
Vă rugăm să observați că varianta recursivă este fundamental diferită.
57
57
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:
59
59
60
60
```js
61
61
if n==1 = x
@@ -65,10 +65,10 @@ pow(x, n) =
65
65
else = x * pow(x, n - 1)
66
66
```
67
67
68
-
1.If`n == 1`, then everything istrivial. 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 estetrivial. 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`.
70
70
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`.
0 commit comments