Skip to content

Commit 5c355cd

Browse files
Object.keys, values, entries tasks
1 parent b5105b7 commit 5c355cd

3 files changed

Lines changed: 21 additions & 30 deletions

File tree

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
```js run demo
22
function sumSalaries(salaries) {
3-
43
let sum = 0;
54
for (let salary of Object.values(salaries)) {
65
sum += salary;
@@ -10,20 +9,20 @@ function sumSalaries(salaries) {
109
}
1110

1211
let salaries = {
13-
"John": 100,
14-
"Pete": 300,
15-
"Mary": 250
12+
John: 100,
13+
Pete: 300,
14+
Mary: 250
1615
};
1716

18-
alert( sumSalaries(salaries) ); // 650
17+
alert(sumSalaries(salaries)); // 650
1918
```
20-
Or, optionally, we could also get the sum using `Object.values` and `reduce`:
19+
20+
أو يمكننا (لو أردنا) معرفة المجموع باستعمال Object.values والتابِع reduce:
2121

2222
```js
23-
// reduce loops over array of salaries,
24-
// adding them up
25-
// and returns the result
23+
// ‫يمرّ reduce على مصفوفة من الرواتب،
24+
// ويجمعها مع بعضها ويُعيد الناتج
2625
function sumSalaries(salaries) {
27-
return Object.values(salaries).reduce((a, b) => a + b, 0) // 650
26+
return Object.values(salaries).reduce((a, b) => a + b, 0); // 650
2827
}
2928
```

1-js/05-data-types/09-keys-values-entries/01-sum-salaries/task.md

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,18 @@ importance: 5
22

33
---
44

5-
# Sum the properties
5+
# مجموع الخاصيات
66

7-
There is a `salaries` object with arbitrary number of salaries.
7+
أمامك كائن salaries وفيه بعض الرواتب. اكتب دالة sumSalaries(salaries) تُعيد مجموع كلّ الرواتب، باستعمال Object.values وحلقة for..of. لو كان الكائن فارغًا فيجب أن يكون الناتج صفرًا 0.
88

9-
Write the function `sumSalaries(salaries)` that returns the sum of all salaries using `Object.values` and the `for..of` loop.
10-
11-
If `salaries` is empty, then the result must be `0`.
12-
13-
For instance:
9+
مثال:
1410

1511
```js
1612
let salaries = {
17-
"John": 100,
18-
"Pete": 300,
19-
"Mary": 250
13+
John: 100,
14+
Pete: 300,
15+
Mary: 250
2016
};
2117

22-
alert( sumSalaries(salaries) ); // 650
18+
alert(sumSalaries(salaries)); // 650
2319
```
24-

1-js/05-data-types/09-keys-values-entries/02-count-properties/task.md

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,17 @@ importance: 5
22

33
---
44

5-
# Count properties
5+
# عدد الخاصيات
66

7-
Write a function `count(obj)` that returns the number of properties in the object:
7+
اكتب دالة باسم count(obj)‎ تُعيد عدد الخاصيات داخل الكائن:
88

99
```js
1010
let user = {
11-
name: 'John',
11+
name: "John",
1212
age: 30
1313
};
1414

15-
alert( count(user) ); // 2
15+
alert(count(user)); // 2
1616
```
1717

18-
Try to make the code as short as possible.
19-
20-
P.S. Ignore symbolic properties, count only "regular" ones.
21-
18+
حاوِل أن تكون الشيفرة بأصغر ما أمكن.

0 commit comments

Comments
 (0)