Skip to content

Commit 2f2a86a

Browse files
committed
translated until line 290
1 parent 0e73223 commit 2f2a86a

File tree

1 file changed

+24
-24
lines changed

1 file changed

+24
-24
lines changed

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

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -195,30 +195,30 @@ Deci ar fi mai precis să spunem că execuția se reia "imediat după subapelare
195195

196196
### pow(2, 1)
197197

198-
The process repeats: a new subcall is made at line `5`, now with arguments `x=2`, `n=1`.
198+
Procesul se repetă: se face un nou subapel la linia `5`, acum cu argumentele `x=2`, `n=1`.
199199

200-
A new execution context is created, the previous one is pushed on top of the stack:
200+
Se creează un nou context de execuție, iar cel anterior este împins în partea de sus a stack-ului:
201201

202202
<ul class="function-execution-context-list">
203203
<li>
204-
<span class="function-execution-context">Context: { x: 2, n: 1, at line 1 }</span>
204+
<span class="function-execution-context">Context: { x: 2, n: 1, la linia 1 }</span>
205205
<span class="function-execution-context-call">pow(2, 1)</span>
206206
</li>
207207
<li>
208-
<span class="function-execution-context">Context: { x: 2, n: 2, at line 5 }</span>
208+
<span class="function-execution-context">Context: { x: 2, n: 2, la linia 5 }</span>
209209
<span class="function-execution-context-call">pow(2, 2)</span>
210210
</li>
211211
<li>
212-
<span class="function-execution-context">Context: { x: 2, n: 3, at line 5 }</span>
212+
<span class="function-execution-context">Context: { x: 2, n: 3, la linia 5 }</span>
213213
<span class="function-execution-context-call">pow(2, 3)</span>
214214
</li>
215215
</ul>
216216

217-
There are 2 old contexts now and 1 currently running for `pow(2, 1)`.
217+
Acum există 2 contexte vechi și 1 în curs de desfășurare pentru `pow(2, 1)`.
218218

219-
### The exit
219+
### Ieșirea
220220

221-
During the execution of `pow(2, 1)`, unlike before, the condition `n == 1` is truthy, so the first branch of `if` works:
221+
În timpul execuției lui `pow(2, 1)`, spre deosebire de înainte, condiția `n == 1` este truthy, astfel încât prima ramură din `if` funcționează:
222222

223223
```js
224224
function pow(x, n) {
@@ -232,42 +232,42 @@ function pow(x, n) {
232232
}
233233
```
234234

235-
There are no more nested calls, so the function finishes, returning `2`.
235+
Nu mai există alte apeluri nested, așa că funcția se termină, returnând `2`.
236236

237-
As the function finishes, its execution context is not needed anymore, so it's removed from the memory. The previous one is restored off the top of the stack:
237+
Deoarece funcția se termină, contextul său de execuție nu mai este necesar, așa că este șters din memorie. Cel anterior este restaurat din vârful stack-ului:
238238

239239

240240
<ul class="function-execution-context-list">
241241
<li>
242-
<span class="function-execution-context">Context: { x: 2, n: 2, at line 5 }</span>
242+
<span class="function-execution-context">Context: { x: 2, n: 2, la linia 5 }</span>
243243
<span class="function-execution-context-call">pow(2, 2)</span>
244244
</li>
245245
<li>
246-
<span class="function-execution-context">Context: { x: 2, n: 3, at line 5 }</span>
246+
<span class="function-execution-context">Context: { x: 2, n: 3, la linia 5 }</span>
247247
<span class="function-execution-context-call">pow(2, 3)</span>
248248
</li>
249249
</ul>
250250

251-
The execution of `pow(2, 2)` is resumed. It has the result of the subcall `pow(2, 1)`, so it also can finish the evaluation of `x * pow(x, n - 1)`, returning `4`.
251+
Se reia execuția lui `pow(2, 2)`. Ea are rezultatul subapelării `pow(2, 1)`, astfel încât poate termina evaluarea lui `x * pow(x, n - 1)`, returnând `4`.
252252

253-
Then the previous context is restored:
253+
Apoi se restabilește contextul anterior:
254254

255255
<ul class="function-execution-context-list">
256256
<li>
257-
<span class="function-execution-context">Context: { x: 2, n: 3, at line 5 }</span>
257+
<span class="function-execution-context">Context: { x: 2, n: 3, la linia 5 }</span>
258258
<span class="function-execution-context-call">pow(2, 3)</span>
259259
</li>
260260
</ul>
261261

262-
When it finishes, we have a result of `pow(2, 3) = 8`.
262+
Când se termină, avem un rezultat `pow(2, 3) = 8`.
263263

264-
The recursion depth in this case was: **3**.
264+
Adâncimea de recursivitate în acest caz a fost: **3**.
265265

266-
As we can see from the illustrations above, recursion depth equals the maximal number of context in the stack.
266+
După cum putem vedea din ilustrațiile de mai sus, adâncimea de recursivitate este egală cu numărul maxim de contexte din stack.
267267

268-
Note the memory requirements. Contexts take memory. In our case, raising to the power of `n` actually requires the memory for `n` contexts, for all lower values of `n`.
268+
Observați cerințele de memorie. Contextele ocupă memorie. În cazul nostru, ridicarea la puterea lui `n` necesită de fapt memorie pentru `n` contexte, pentru toate valorile mai mici ale lui `n`.
269269

270-
A loop-based algorithm is more memory-saving:
270+
Un algoritm bazat pe loop este mai economic pentru memorie:
271271

272272
```js
273273
function pow(x, n) {
@@ -281,13 +281,13 @@ function pow(x, n) {
281281
}
282282
```
283283

284-
The iterative `pow` uses a single context changing `i` and `result` in the process. Its memory requirements are small, fixed and do not depend on `n`.
284+
Iterativul `pow` utilizează un singur context care schimbă `i` și `result` în timpul procesului. Cerințele sale de memorie sunt mici, fixe și nu depind de `n`.
285285

286-
**Any recursion can be rewritten as a loop. The loop variant usually can be made more effective.**
286+
**Orice recursivitate poate fi rescrisă ca un loop. De obicei, varianta loop poate fi făcută mai eficientă.**
287287

288-
...But sometimes the rewrite is non-trivial, especially when a function uses different recursive subcalls depending on conditions and merges their results or when the branching is more intricate. And the optimization may be unneeded and totally not worth the efforts.
288+
...Dar uneori rescrierea nu este trivială, în special atunci când o funcție utilizează diferite subapelări recursive în funcție de condiții și fuzionează rezultatele acestora sau când ramificarea este mai complexă. Iar optimizarea poate fi inutilă și nu merită în totalitate eforturile depuse.
289289

290-
Recursion can give a shorter code, easier to understand and support. Optimizations are not required in every place, mostly we need a good code, that's why it's used.
290+
Recursivitatea poate oferi un cod mai scurt, ușor de înțeles și de susținut. Optimizările nu sunt necesare în orice loc, de cele mai multe ori avem nevoie de un cod bun, de aceea este folosit.
291291

292292
## Recursive traversals
293293

0 commit comments

Comments
 (0)