File tree 9 files changed +237
-241
lines changed
1-js/04-object-basics/01-object
9 files changed +237
-241
lines changed Original file line number Diff line number Diff line change @@ -2,13 +2,12 @@ importance: 5
2
2
3
3
---
4
4
5
- # Hello, object
5
+ # Salut, obiect
6
6
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:
14
8
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 1
1
function isEmpty ( obj ) {
2
2
for ( let key in obj ) {
3
- // if the loop has started, there is a property
3
+ // dacă bucla a pornit, există o proprietate
4
4
return false ;
5
5
}
6
6
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
2
2
3
3
---
4
4
5
- # Check for emptiness
5
+ # Verificați dacă este gol
6
6
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 .
8
8
9
- Should work like that :
9
+ Ar trebui să funcționeze așa :
10
10
11
11
``` js
12
12
let schedule = {};
@@ -17,4 +17,3 @@ schedule["8:30"] = "get up";
17
17
18
18
alert ( isEmpty (schedule) ); // false
19
19
```
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 .
2
2
3
- The ` const ` only protects the variable itself from changing.
3
+ Cuvântul ` const ` protejează numai modificarea variabilei în sine.
4
4
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 .
6
6
7
7
``` js run
8
8
const user = {
9
9
name: " John"
10
10
};
11
11
12
12
* ! *
13
- // works
13
+ // funcționează
14
14
user .name = " Pete" ;
15
15
*/ ! *
16
16
17
- // error
17
+ // eroare
18
18
user = 123 ;
19
19
```
Original file line number Diff line number Diff line change @@ -2,17 +2,17 @@ importance: 5
2
2
3
3
---
4
4
5
- # Constant objects ?
5
+ # Obiecte constante ?
6
6
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 ?
8
8
9
9
``` js
10
10
const user = {
11
11
name: " John"
12
12
};
13
13
14
14
* ! *
15
- // does it work ?
15
+ // funcționează ?
16
16
user .name = " Pete" ;
17
17
*/ ! *
18
18
```
Original file line number Diff line number Diff line change @@ -2,9 +2,9 @@ importance: 5
2
2
3
3
---
4
4
5
- # Sum object properties
5
+ # Însumați proprietățile obiectului
6
6
7
- We have an object storing salaries of our team :
7
+ Avem un obiect care stochează salariile persoanelor din echipa noastră :
8
8
9
9
``` js
10
10
let salaries = {
@@ -14,6 +14,6 @@ let salaries = {
14
14
}
15
15
```
16
16
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 ` .
18
18
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
2
2
3
3
---
4
4
5
- # Multiply numeric properties by 2
5
+ # Multiplicați proprietățile numerice cu 2
6
6
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 ` .
8
8
9
9
For instance:
10
10
11
11
``` js
12
- // before the call
12
+ // înainte de apelare
13
13
let menu = {
14
14
width: 200 ,
15
15
height: 300 ,
@@ -18,16 +18,14 @@ let menu = {
18
18
19
19
multiplyNumeric (menu);
20
20
21
- // after the call
21
+ // după apelare
22
22
menu = {
23
23
width: 400 ,
24
24
height: 600 ,
25
25
title: " My menu"
26
26
};
27
27
```
28
28
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.
33
30
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