Skip to content

Objects #39

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Dec 11, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 7 additions & 8 deletions 1-js/04-object-basics/01-object/2-hello-object/task.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@ importance: 5

---

# Hello, object
# Salut, obiect

Write the code, one line for each action:

1. Create an empty object `user`.
2. Add the property `name` with the value `John`.
3. Add the property `surname` with the value `Smith`.
4. Change the value of the `name` to `Pete`.
5. Remove the property `name` from the object.
Scrieți codul, câte o linie pentru fiecare acțiune:

1. Crează un obiect gol `user`.
2. Adaugă proprietatea `name` cu valoarea `John`.
3. Adaugă proprietatea `surname` cu valoarea `Smith`.
4. Modifică valoare proprietății `name` în `Pete`.
5. Șterge proprietatea `name` din obiect.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
function isEmpty(obj) {
for (let key in obj) {
// if the loop has started, there is a property
// dacă bucla a pornit, există o proprietate
return false;
}
return true;
Expand Down
2 changes: 1 addition & 1 deletion 1-js/04-object-basics/01-object/3-is-empty/solution.md
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Just loop over the object and `return false` immediately if there's at least one property.
Se va executa o buclă asupra obiectului și se va `returna false` imediat ce se întalnește o proprietate.
7 changes: 3 additions & 4 deletions 1-js/04-object-basics/01-object/3-is-empty/task.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ importance: 5

---

# Check for emptiness
# Verificați dacă este gol

Write the function `isEmpty(obj)` which returns `true` if the object has no properties, `false` otherwise.
Scrieți funcția `isEmpty(obj)` care returnează `true` dacă obiectul nu are proprietăți și `false` în caz contrar.

Should work like that:
Ar trebui să funcționeze așa:

```js
let schedule = {};
Expand All @@ -17,4 +17,3 @@ schedule["8:30"] = "get up";

alert( isEmpty(schedule) ); // false
```

10 changes: 5 additions & 5 deletions 1-js/04-object-basics/01-object/4-const-object/solution.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
Sure, it works, no problem.
Bineînțeles, funcționează fără probleme.

The `const` only protects the variable itself from changing.
Cuvântul `const` protejează numai modificarea variabilei în sine.

In other words, `user` stores a reference to the object. And it can't be changed. But the content of the object can.
Cu alte cuvinte, `user` stochează o referință a obiectului. Și nu poate fi modificată. În schimb, conținutul obiectului se poate modifica.

```js run
const user = {
name: "John"
};

*!*
// works
// funcționează
user.name = "Pete";
*/!*

// error
// eroare
user = 123;
```
6 changes: 3 additions & 3 deletions 1-js/04-object-basics/01-object/4-const-object/task.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@ importance: 5

---

# Constant objects?
# Obiecte constante?

Is it possible to change an object declared with `const`? What do you think?
Este posibilă modificarea unui obiect declarat cu `const`? Ce credeți?

```js
const user = {
name: "John"
};

*!*
// does it work?
// funcționează?
user.name = "Pete";
*/!*
```
8 changes: 4 additions & 4 deletions 1-js/04-object-basics/01-object/5-sum-object/task.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ importance: 5

---

# Sum object properties
# Însumați proprietățile obiectului

We have an object storing salaries of our team:
Avem un obiect care stochează salariile persoanelor din echipa noastră:

```js
let salaries = {
Expand All @@ -14,6 +14,6 @@ let salaries = {
}
```

Write the code to sum all salaries and store in the variable `sum`. Should be `390` in the example above.
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`.

If `salaries` is empty, then the result must be `0`.
Dacă obiectul `salaries` este gol, atunci rezultatul trebuie să fie `0`.
14 changes: 6 additions & 8 deletions 1-js/04-object-basics/01-object/8-multiply-numeric/task.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ importance: 3

---

# Multiply numeric properties by 2
# Multiplicați proprietățile numerice cu 2

Create a function `multiplyNumeric(obj)` that multiplies all numeric properties of `obj` by `2`.
Creați o funcție `multiplyNumeric(obj)` care multiplică fiecare proprietate a `obj` cu `2`.

For instance:

```js
// before the call
// înainte de apelare
let menu = {
width: 200,
height: 300,
Expand All @@ -18,16 +18,14 @@ let menu = {

multiplyNumeric(menu);

// after the call
// după apelare
menu = {
width: 400,
height: 600,
title: "My menu"
};
```

Please note that `multiplyNumeric` does not need to return anything. It should modify the object in-place.

P.S. Use `typeof` to check for a number here.

Vă rugăm să remarcați că `multiplyNumeric` nu are nevoie să returneze ceva. Ar trebui să modifice obiectul pe loc.

P.S. Folosiți `typeof` pentru a verifica dacă este un număr.
Loading