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
+8-8Lines changed: 8 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -73,19 +73,19 @@ Putem de asemenea spune că `pow` *se apelează recursiv pe sine* până când `
73
73

74
74
75
75
76
-
For example, to calculate `pow(2, 4)` the recursive variant does these steps:
76
+
De exemplu, pentru a calcula `pow(2, 4)`, varianta recursivă face acești pași:
77
77
78
78
1.`pow(2, 4) = 2 * pow(2, 3)`
79
79
2.`pow(2, 3) = 2 * pow(2, 2)`
80
80
3.`pow(2, 2) = 2 * pow(2, 1)`
81
81
4.`pow(2, 1) = 2`
82
82
83
-
So, the recursion reduces a function call to a simpler one, and then -- to even more simpler, and so on, until the result becomes obvious.
83
+
Așadar, recursivitatea reduce un apel de funcție la unul mai simplu, și apoi--la unul și mai simplu, și așa mai departe, până când rezultatul devine evident.
84
84
85
-
````smart header="Recursion is usually shorter"
86
-
A recursive solution is usually shorter than an iterative one.
85
+
````smart header="Recursiunea este de obicei mai scurtă"
86
+
O soluție recursivă este de obicei mai scurtă decât una iterativă.
87
87
88
-
Here we can rewrite the same using the conditional operator `?` instead of `if` to make `pow(x, n)` more terse and still very readable:
88
+
Aici putem rescrie același lucru folosind operatorul condițional `?`în loc de `if`pentru a face `pow(x, n)`mai consic și totuși foarte ușor de citit:
89
89
90
90
```js run
91
91
function pow(x, n) {
@@ -94,11 +94,11 @@ function pow(x, n) {
94
94
```
95
95
````
96
96
97
-
The maximal number of nested calls (including the first one) is called *recursion depth*. In our case, it will be exactly `n`.
97
+
Numărul maxim de apelurinested(inclusiv primul apel) se numește *profunzime de recursiune*. În cazul nostru, acesta va fi exact`n`.
98
98
99
-
The maximal recursion depth is limited by JavaScript engine. We can rely on it being 10000, some engines allow more, but 100000 is probably out of limit for the majority of them. There are automatic optimizations that help alleviate this ("tail calls optimizations"), but they are not yet supported everywhere and work only in simple cases.
99
+
Profunzimea maximă de recursivitate este limitată de motorul JavaScript. Ne putem baza pe faptul că este 10000, unele motoare permit mai mult, dar100000este probabil în afara limitei pentru majoritatea acestora. Există optimizări automate care ajută la atenuarea acestui aspect("tail calls optimizations"), dar acestea nu sunt încă acceptate peste tot și funcționează doar în cazuri simple.
100
100
101
-
That limits the application of recursion, but it still remains very wide. There are many tasks where recursive way of thinking gives simpler code, easier to maintain.
101
+
Acest lucru limitează aplicarea recursivității, dar aceasta rămâne totuși foarte largă. Există multe sarcini în care modul recursiv de gândire oferă un cod mai simplu, mai ușor de întreținut.
0 commit comments