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
sum += sumSalaries(subdep); // recursively call for subdepartments, sum the results
368
+
sum += sumSalaries(subdep); // apelează recursiv pentru subdepartamente, însumează rezultatele
369
369
}
370
370
return sum;
371
371
}
@@ -375,18 +375,18 @@ function sumSalaries(department) {
375
375
alert(sumSalaries(company)); // 7700
376
376
```
377
377
378
-
The code is short and easy to understand (hopefully?). That's the power of recursion. It also works for any level of subdepartment nesting.
378
+
Codul este scurt și ușor de înțeles (sperăm?). Aceasta este puterea recursivității. Funcționează de asemenea pentru orice nivel nested a subdepartamentului.
379
379
380
-
Here's the diagram of calls:
380
+
Iată diagrama de apeluri:
381
381
382
382

383
383
384
-
We can easily see the principle:for an object`{...}`subcalls are made, while arrays `[...]`are the "leaves"of the recursion tree, they give immediate result.
384
+
Putem vedea cu ușurință principiul: pentru un obiect`{...}`se fac subapeluri, în timp ce array-urile `[...]`sunt "frunzele" din recursion tree, ele dau un rezultat imediat.
385
385
386
-
Note that the code uses smart features that we've covered before:
386
+
Observați că codul folosește caracteristici inteligente pe care le-am mai acoperit:
387
387
388
-
- Method `arr.reduce` explained in the chapter <info:array-methods> to get the sum of the array.
389
-
- Loop `for(val of Object.values(obj))` to iterate over object values: `Object.values` returns an array of them.
388
+
-Metoda`arr.reduce`explicată în capitolul <info:array-methods>pentru a obține suma array-ului.
389
+
-Bucla`for(val of Object.values(obj))`pentru a itera peste valorile obiectului:`Object.values`returnează un array al acestora.
0 commit comments