Skip to content

Commit 0453a6a

Browse files
committed
Translate function-object to Ar
1 parent c5adfd4 commit 0453a6a

5 files changed

Lines changed: 124 additions & 103 deletions

File tree

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11

2-
The solution uses `count` in the local variable, but addition methods are written right into the `counter`. They share the same outer lexical environment and also can access the current `count`.
2+
الحل يستخدم `count` في المتغير المحلي, لكن الوظائف الإضافية تمت كتابتها بجانب `counter`.
3+
إنهم يتشاركون نفس الحسد اللغوي ويمكنهم أيضاً الوصول إلى القيمة الحالية `count`.

1-js/06-advanced-functions/06-function-object/2-counter-inc-dec/task.md

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

33
---
44

5-
# Set and decrease for counter
5+
# وضع و تقليل للعداد
66

7-
Modify the code of `makeCounter()` so that the counter can also decrease and set the number:
7+
عدل الكود الخاص بالدالة `makeCounter()` بحيث يمكن للعداد أيضاً أن يخفض أو يضبط العدد:
88

9-
- `counter()` should return the next number (as before).
10-
- `counter.set(value)` should set the counter to `value`.
11-
- `counter.decrease()` should decrease the counter by 1.
9+
- `counter()` يجب أن تُرجِع الرقم التالي (كما في السابق).
10+
- `counter.set(value)` يجب أن تضع قيمة العداد إلي `value`.
11+
- `counter.decrease()` يجب أن تقلل قيمة العداد بفارق واحد.
1212

13-
See the sandbox code for the complete usage example.
13+
إنظر لصندوق الكود بالأسفل لإستخدام المثال كاملاً
14+
15+
ملحوظة: يمكنك إستخدام إما الإغلاق أو خاصية الدالة للمحافظة على العداد الحالي. أو تستخدم الإثنين إذا أردت.
1416

15-
P.S. You can use either a closure or the function property to keep the current count. Or write both variants.

1-js/06-advanced-functions/06-function-object/5-sum-many-brackets/solution.md

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1+
1. *أيّما كانت* الطريقة التي سنستعملها ليعمل هذا الشيء، فلا بدّ أن تُرجع `‎sum‎` دالة.
2+
2. على تلك الدالة أن تحفظ القيمة الحالية بين كلّ استدعاء والآخر داخل الذاكرة.
3+
3. حسب المهمّة المُعطاة، يجب أن تتحول الدالة إلى عدد حين نستعملها في `‎==‎`. الدوال كائنات لذا فعملية التحويل ستنفع كما شرحنا في فصل «التحويل من كائن إلى قيمة أولية»، ويمكن أن نقدّم تابِعًا خاصًا يُعيد ذلك العدد.
14

2-
1. For the whole thing to work *anyhow*, the result of `sum` must be function.
3-
2. That function must keep in memory the current value between calls.
4-
3. According to the task, the function must become the number when used in `==`. Functions are objects, so the conversion happens as described in the chapter <info:object-toprimitive>, and we can provide our own method that returns the number.
5+
إلى الشيفرة:
56

6-
Now the code:
7-
8-
```js run
7+
```js
98
function sum(a) {
109

1110
let currentSum = a;
@@ -28,28 +27,33 @@ alert( sum(6)(-1)(-2)(-3) ); // 0
2827
alert( sum(0)(1)(2)(3)(4)(5) ); // 15
2928
```
3029

31-
Please note that the `sum` function actually works only once. It returns function `f`.
30+
لاحظ بأنّ دالة `sum` تعمل مرّة واحدة فقط لا غير، وتُعيد الدالة `‎f‎`.
3231

33-
Then, on each subsequent call, `f` adds its parameter to the sum `currentSum`, and returns itself.
32+
وبعدها في كلّ استدعاء يليها، تُضيف `‎f‎` المُعامل إلى المجموع `currentSum` وتُعيد نفسها.
3433

35-
**There is no recursion in the last line of `f`.**
34+
**لا نستعمل التعاود في آخر سطر من `‎f‎`.**
3635

37-
Here is what recursion looks like:
36+
هذا شكل التعاود:
3837

3938
```js
4039
function f(b) {
4140
currentSum += b;
42-
return f(); // <-- recursive call
41+
return f(); // <-- استدعاء تعاودي
4342
}
4443
```
4544

46-
And in our case, we just return the function, without calling it:
45+
بينما في حالتنا نُعيد الدالة دون استدعائها:
4746

4847
```js
4948
function f(b) {
5049
currentSum += b;
51-
return f; // <-- does not call itself, returns itself
50+
return f; // <-- لا تستدعي نفسها، بل تُعيد نفسها
5251
}
5352
```
5453

55-
This `f` will be used in the next call, again return itself, so many times as needed. Then, when used as a number or a string -- the `toString` returns the `currentSum`. We could also use `Symbol.toPrimitive` or `valueOf` here for the conversion.
54+
وستُستعمل `‎f‎` هذه في الاستدعاء التالي، وتُعيد نفسها ثانيةً مهما لزم. وبعدها حين نستعمل العدد أو السلسلة النصية، يُعيد التابِع `‎toString‎` المجموع `‎currentSum‎`. يمكن أيضًا أن نستعمل `‎Symbol.toPrimitive‎` أو `‎valueOf‎` لإجراء عملية التحويل.
55+
56+
ترجمة -وبتصرف- للفصل [Function object, NFE](https://javascript.info/function-object) من كتاب [The JavaScript language](https://javascript.info/js)
57+
58+
59+
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
importance: 2
22

33
---
4+
# إجمع عن طريق مجموعة عشوائية من الأقواس
45

5-
# Sum with an arbitrary amount of brackets
6+
إكتب دالة `sum` التى تعمل هكذا:
67

7-
Write function `sum` that would work like this:
88

99
```js
1010
sum(1)(2) == 3; // 1 + 2
@@ -14,4 +14,4 @@ sum(6)(-1)(-2)(-3) == 0
1414
sum(0)(1)(2)(3)(4)(5) == 15
1515
```
1616

17-
P.S. Hint: you may need to setup custom object to primitive conversion for your function.
17+
تلميح: ربما تحتاج إلي كائن مخصوص للتحويل البدائي لدالتك.

0 commit comments

Comments
 (0)