File tree Expand file tree Collapse file tree 9 files changed +237
-241
lines changed
1-js/04-object-basics/01-object Expand file tree Collapse file tree 9 files changed +237
-241
lines changed Original file line number Diff line number Diff line change @@ -2,13 +2,12 @@ importance: 5
22
33---
44
5- # Hello, object
5+ # Salut, obiect
66
7- Write the code, one line for each action:
8-
9- 1 . Create an empty object ` user ` .
10- 2 . Add the property ` name ` with the value ` John ` .
11- 3 . Add the property ` surname ` with the value ` Smith ` .
12- 4 . Change the value of the ` name ` to ` Pete ` .
13- 5 . Remove the property ` name ` from the object.
7+ Scrieți codul, câte o linie pentru fiecare acțiune:
148
9+ 1 . Crează un obiect gol ` user ` .
10+ 2 . Adaugă proprietatea ` name ` cu valoarea ` John ` .
11+ 3 . Adaugă proprietatea ` surname ` cu valoarea ` Smith ` .
12+ 4 . Modifică valoare proprietății ` name ` în ` Pete ` .
13+ 5 . Șterge proprietatea ` name ` din obiect.
Original file line number Diff line number Diff line change 11function isEmpty ( obj ) {
22 for ( let key in obj ) {
3- // if the loop has started, there is a property
3+ // dacă bucla a pornit, există o proprietate
44 return false ;
55 }
66 return true ;
Original file line number Diff line number Diff line change 1- Just loop over the object and ` return false` immediately if there's at least one property .
1+ Se va executa o buclă asupra obiectului și se va ` returna false` imediat ce se întalnește o proprietate .
Original file line number Diff line number Diff line change @@ -2,11 +2,11 @@ importance: 5
22
33---
44
5- # Check for emptiness
5+ # Verificați dacă este gol
66
7- Write the function ` isEmpty(obj) ` which returns ` true ` if the object has no properties, ` false ` otherwise .
7+ Scrieți funcția ` isEmpty(obj) ` care returnează ` true ` dacă obiectul nu are proprietăți și ` false ` în caz contrar .
88
9- Should work like that :
9+ Ar trebui să funcționeze așa :
1010
1111``` js
1212let schedule = {};
@@ -17,4 +17,3 @@ schedule["8:30"] = "get up";
1717
1818alert ( isEmpty (schedule) ); // false
1919```
20-
Original file line number Diff line number Diff line change 1- Sure, it works, no problem .
1+ Bineînțeles, funcționează fără probleme .
22
3- The ` const ` only protects the variable itself from changing.
3+ Cuvântul ` const ` protejează numai modificarea variabilei în sine.
44
5- In other words , ` user ` stores a reference to the object. And it can't be changed. But the content of the object can .
5+ Cu alte cuvinte , ` user ` stochează o referință a obiectului. Și nu poate fi modificată. În schimb, conținutul obiectului se poate modifica .
66
77``` js run
88const user = {
99 name: " John"
1010};
1111
1212* ! *
13- // works
13+ // funcționează
1414user .name = " Pete" ;
1515*/ ! *
1616
17- // error
17+ // eroare
1818user = 123 ;
1919```
Original file line number Diff line number Diff line change @@ -2,17 +2,17 @@ importance: 5
22
33---
44
5- # Constant objects ?
5+ # Obiecte constante ?
66
7- Is it possible to change an object declared with ` const ` ? What do you think ?
7+ Este posibilă modificarea unui obiect declarat cu ` const ` ? Ce credeți ?
88
99``` js
1010const user = {
1111 name: " John"
1212};
1313
1414* ! *
15- // does it work ?
15+ // funcționează ?
1616user .name = " Pete" ;
1717*/ ! *
1818```
Original file line number Diff line number Diff line change @@ -2,9 +2,9 @@ importance: 5
22
33---
44
5- # Sum object properties
5+ # Însumați proprietățile obiectului
66
7- We have an object storing salaries of our team :
7+ Avem un obiect care stochează salariile persoanelor din echipa noastră :
88
99``` js
1010let salaries = {
@@ -14,6 +14,6 @@ let salaries = {
1414}
1515```
1616
17- Write the code to sum all salaries and store in the variable ` sum ` . Should be ` 390 ` in the example above .
17+ Scrieți codul pentru a însuma toate salariile și salvați suma în variabila ` sum ` . Rezultatul din exemplul de mai sus ar trebui să fie ` 390 ` .
1818
19- If ` salaries ` is empty, then the result must be ` 0 ` .
19+ Dacă obiectul ` salaries ` este gol, atunci rezultatul trebuie să fie ` 0 ` .
Original file line number Diff line number Diff line change @@ -2,14 +2,14 @@ importance: 3
22
33---
44
5- # Multiply numeric properties by 2
5+ # Multiplicați proprietățile numerice cu 2
66
7- Create a function ` multiplyNumeric(obj) ` that multiplies all numeric properties of ` obj ` by ` 2 ` .
7+ Creați o funcție ` multiplyNumeric(obj) ` care multiplică fiecare proprietate a ` obj ` cu ` 2 ` .
88
99For instance:
1010
1111``` js
12- // before the call
12+ // înainte de apelare
1313let menu = {
1414 width: 200 ,
1515 height: 300 ,
@@ -18,16 +18,14 @@ let menu = {
1818
1919multiplyNumeric (menu);
2020
21- // after the call
21+ // după apelare
2222menu = {
2323 width: 400 ,
2424 height: 600 ,
2525 title: " My menu"
2626};
2727```
2828
29- Please note that ` multiplyNumeric ` does not need to return anything. It should modify the object in-place.
30-
31- P.S. Use ` typeof ` to check for a number here.
32-
29+ Vă rugăm să remarcați că ` multiplyNumeric ` nu are nevoie să returneze ceva. Ar trebui să modifice obiectul pe loc.
3330
31+ P.S. Folosiți ` typeof ` pentru a verifica dacă este un număr.
You can’t perform that action at this time.
0 commit comments