Skip to content

Commit 2ce27aa

Browse files
committed
Translate numbers to AR
1 parent e8eec52 commit 2ce27aa

12 files changed

Lines changed: 259 additions & 319 deletions

File tree

1-js/05-data-types/02-number/1-sum-interface/solution.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,4 @@ let b = +prompt("The second number?", "");
77
alert( a + b );
88
```
99

10-
Note the unary plus `+` before `prompt`. It immediately converts the value to a number.
11-
12-
Otherwise, `a` and `b` would be string their sum would be their concatenation, that is: `"1" + "2" = "12"`.
10+
لاحظ عامل الجمع الأحادي `+` قبل `prompt`. يحوِّل القيم إلى أعداد. وإلا فإن `a` و `b` ستكون نصوصًا وسيكون مجموعهما بدمجهما: `"1" + "2" = "12"`.
Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
importance: 5
1+
الأهمية: 5
22

33
---
44

5-
# Sum numbers from the visitor
5+
# جمع الأعداد من الزائر
66

7-
Create a script that prompts the visitor to enter two numbers and then shows their sum.
7+
انشِئ سكربت يتيح للمستخدم ادخال رقمين ثم أعرض مجموعهما.
88

99
[demo]
1010

11-
P.S. There is a gotcha with types.
Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,30 @@
1-
Internally the decimal fraction `6.35` is an endless binary. As always in such cases, it is stored with a precision loss.
2-
3-
Let's see:
1+
الجزء `6.35` هو عبارة عن عدد غير منتهي في الصيغة الثنائية. وكجميع الحالات المشابهة، يُخَزَّن مع ضياع في الدقة. لنرَ:
42

53
```js run
64
alert( 6.35.toFixed(20) ); // 6.34999999999999964473
75
```
86

9-
The precision loss can cause both increase and decrease of a number. In this particular case the number becomes a tiny bit less, that's why it rounded down.
10-
11-
And what's for `1.35`?
7+
قد يتسبب ضياع الدقة في زيادة أو نقصان أي عدد. يكون العدد في هذه الحالة أقل بقليل من قيمته الفعلية، ولهذا يُدَوَّر للأسفل. ماذا عن العدد `1.35`؟
128

139
```js run
1410
alert( 1.35.toFixed(20) ); // 1.35000000000000008882
1511
```
1612

17-
Here the precision loss made the number a little bit greater, so it rounded up.
13+
جعل ضياع الدقة هذا الرقم أكبر بقليل مما هو عليه مما تسبب في تقريبه للأعلى.
14+
15+
**كيف يمكننا حل مشكلة تقريب العدد `6.35` حتى يُدَوَّر بالشكل الصحيح**
1816

19-
**How can we fix the problem with `6.35` if we want it to be rounded the right way?**
17+
يجب أن نحوله إلى عدد صحيح قبل التقريب:
2018

21-
We should bring it closer to an integer prior to rounding:
2219

2320
```js run
2421
alert( (6.35 * 10).toFixed(20) ); // 63.50000000000000000000
2522
```
2623

27-
Note that `63.5` has no precision loss at all. That's because the decimal part `0.5` is actually `1/2`. Fractions divided by powers of `2` are exactly represented in the binary system, now we can round it:
24+
لاحظ عدم وجود أي ضياع في دقة العدد `63.5`. ذلك لأن الجزء العشري `0.5` يساوي `1/2`. يمكن تمثيل الأجزاء المقسومة على `2` تُمَثَّل بشكل صحيح في النظام الثنائي. يمكننا تقريب العدد الآن:
2825

2926

3027
```js run
31-
alert( Math.round(6.35 * 10) / 10); // 6.35 -> 63.5 -> 64(rounded) -> 6.4
28+
alert( Math.round(6.35 * 10) / 10); // 6.35 -> 63.5 -> 64(مقرب) -> 6.4
3229
```
3330

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,24 @@
1-
importance: 4
1+
الأهمية: 4
22

33
---
44

5-
# Why 6.35.toFixed(1) == 6.3?
5+
# لماذا ‎6.35.toFixed(1) == 6.3؟
66

7-
According to the documentation `Math.round` and `toFixed` both round to the nearest number: `0..4` lead down while `5..9` lead up.
87

9-
For instance:
8+
تُدَوِّر كلًا من `Math.round` و `toFixed` العدد إلى أقرب عدد له وفقًا للتوثيق: الأجزاء من `0..4` تُدَوَّر للأسفل، بينما الأجزاء `5..9` تثدَوَّر للأعلى.
9+
10+
مثلًا:
11+
1012

1113
```js run
1214
alert( 1.35.toFixed(1) ); // 1.4
1315
```
1416

15-
In the similar example below, why is `6.35` rounded to `6.3`, not `6.4`?
17+
في المثال المشابه أدناه، لِمَ تُدَوَّر `6.35` إلى `6.3`، وليس `6.4`؟
1618

1719
```js run
1820
alert( 6.35.toFixed(1) ); // 6.3
1921
```
2022

21-
How to round `6.35` the right way?
23+
كيف نُدَوِّر `6.35` بالطريقة الصحيحة؟
2224

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
1-
importance: 5
1+
الأهمية: 5
22

33
---
44

5-
# Repeat until the input is a number
5+
# كرر حتى يصبح المُدخَل عددًا
66

7-
Create a function `readNumber` which prompts for a number until the visitor enters a valid numeric value.
7+
أنشِئ الدالة `readNumber` والتي تطلب من الزائر إدخال عدد حتى يقوم بإدخال قيمة عددية صحيحة. يجب أن تكون القيمة المُرجَعة عددًا.
88

9-
The resulting value must be returned as a number.
10-
11-
The visitor can also stop the process by entering an empty line or pressing "CANCEL". In that case, the function should return `null`.
9+
يمكن للزائر إيقاف العملية بإدخال سطر فارغ أو الضغط على "CANCEL". يجب أن تُرجِع الدالة `null` في هذه الحالة.
1210

1311
[demo]
1412

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
That's because `i` would never equal `10`.
2-
3-
Run it to see the *real* values of `i`:
1+
ذلك لأن `i` لن يساوي `10` أبدًا. نفذ الشيفرة التالية لرؤية قيم `i`:
42

53
```js run
64
let i = 0;
@@ -10,8 +8,4 @@ while (i < 11) {
108
}
119
```
1210

13-
None of them is exactly `10`.
14-
15-
Such things happen because of the precision losses when adding fractions like `0.2`.
16-
17-
Conclusion: evade equality checks when working with decimal fractions.
11+
لا توجد قيمة تساوي `10` تمامًا. تحدث مثل هذه الأمور بسبب ضياع الدقة عند إضافة الأجزاء مثل `0.2`. الخلاصة، تجنب التحقق من المساواة عند التعامل مع الأجزاء العشرية.

1-js/05-data-types/02-number/4-endless-loop-error/task.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
importance: 4
1+
الأهمية: 4
22

33
---
44

5-
# An occasional infinite loop
5+
# حلقة غير منتهية أحيانًا
66

7-
This loop is infinite. It never ends. Why?
7+
الحلقة التالية غير منتهية، ولا تتوقف أبدًا. لماذا؟
88

99
```js
1010
let i = 0;

1-js/05-data-types/02-number/8-random-min-max/solution.md

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
1-
We need to "map" all values from the interval 0..1 into values from `min` to `max`.
1+
نريد تعيين جميع القيم من الفترة 0…1 إلى القيم من `min` إلى `max`. يمكن القيام بذلك في مرحلتين:
2+
1. إذا ضربنا قيمة عشوائية من 0…1 في `max-min`. فإن فترة القيم الممكنة تزيد `0..1` إلى `0..max-min`.
3+
2. إذا أضفنا `min` الآن، تصبح الفترة من `min` إلى `max`.
24

3-
That can be done in two stages:
5+
الدالة:
46

5-
1. If we multiply a random number from 0..1 by `max-min`, then the interval of possible values increases `0..1` to `0..max-min`.
6-
2. Now if we add `min`, the possible interval becomes from `min` to `max`.
7-
8-
The function:
97

108
```js run
119
function random(min, max) {

1-js/05-data-types/02-number/8-random-min-max/task.md

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
1-
importance: 2
1+
الأهمية: 2
22

33
---
44

5-
# A random number from min to max
5+
# رقم عشوائي من العدد الأدنى إلى الأقصى
66

7-
The built-in function `Math.random()` creates a random value from `0` to `1` (not including `1`).
7+
تُنشِئ الدالة `Math.random()` المُضَمَنَة في اللغة قيمة عشوائية بين `0` و `1` (ليس بما في ذلك `1`). اكتب الدالة `random(min, max)‎` لتوليد عدد عشري عشوائي من `min` إلى `max` (بما لا يتضمن `max`).
88

9-
Write the function `random(min, max)` to generate a random floating-point number from `min` to `max` (not including `max`).
9+
أمثلة عن عملها:
1010

11-
Examples of its work:
1211

1312
```js
1413
alert( random(1, 5) ); // 1.2345623452
Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
# The simple but wrong solution
1+
# الطريقة السهلة والخطأ
22

3-
The simplest, but wrong solution would be to generate a value from `min` to `max` and round it:
3+
الحل الأسهل لكنه خطأ سيكون بتوليد قيمة من `min` إلى `max` وتقريبها:
44

55
```js run
66
function randomInteger(min, max) {
@@ -11,28 +11,26 @@ function randomInteger(min, max) {
1111
alert( randomInteger(1, 3) );
1212
```
1313

14-
The function works, but it is incorrect. The probability to get edge values `min` and `max` is two times less than any other.
14+
الدالة تعمل لكنها خطأ. احتمال ظهور القيم الطرفية `min` و `max` أقل بمرتين من باقي القيم. إن شغلنا المثال أعلاه لعدة مرات، فينرى ظهور `2` بصورة أكبر.
1515

16-
If you run the example above many times, you would easily see that `2` appears the most often.
17-
18-
That happens because `Math.round()` gets random numbers from the interval `1..3` and rounds them as follows:
16+
يحدث ذلك لأن `Math.round()‎` تأخذ رقما من الفترة `1..3` وتُدَوِرها كما يلي:
1917

2018
```js no-beautify
2119
values from 1 ... to 1.4999999999 become 1
2220
values from 1.5 ... to 2.4999999999 become 2
2321
values from 2.5 ... to 2.9999999999 become 3
2422
```
2523

26-
Now we can clearly see that `1` gets twice less values than `2`. And the same with `3`.
24+
نلاحظ الآن أن لدى `1` قيم أقل بمرتين من `2` وكذلك `3`.
2725

28-
# The correct solution
26+
# الطريقة الصحيحة
2927

30-
There are many correct solutions to the task. One of them is to adjust interval borders. To ensure the same intervals, we can generate values from `0.5 to 3.5`, thus adding the required probabilities to the edges:
28+
يوجد العديد من الطرق الصحيحة لحل هذه المهمة. إحداها هو بتعديل حدود الفترة. للتأكد من وجود فرص متساوية، نُوَلِّد قيمًا من `0.5` إلى `3.5`، ثم إضافة الاحتمالات الممكنة للأطراف:
3129

3230
```js run
3331
*!*
3432
function randomInteger(min, max) {
35-
// now rand is from (min-0.5) to (max+0.5)
33+
// (max+0.5) إلى (min-0.5) التقريب الآن من
3634
let rand = min - 0.5 + Math.random() * (max - min + 1);
3735
return Math.round(rand);
3836
}
@@ -41,12 +39,12 @@ function randomInteger(min, max) {
4139
alert( randomInteger(1, 3) );
4240
```
4341

44-
An alternative way could be to use `Math.floor` for a random number from `min` to `max+1`:
42+
طريقة بديلة هي استخدام الدالة `Math.floor` لرقم عشوائي من `min` إلى `max+1`:
4543

4644
```js run
4745
*!*
4846
function randomInteger(min, max) {
49-
// here rand is from min to (max+1)
47+
// (max+1) إلى min التقريب الآن من
5048
let rand = min + Math.random() * (max + 1 - min);
5149
return Math.floor(rand);
5250
}
@@ -55,12 +53,12 @@ function randomInteger(min, max) {
5553
alert( randomInteger(1, 3) );
5654
```
5755

58-
Now all intervals are mapped this way:
56+
جميع الفترات أصبحت متوازنة الآن:
5957

6058
```js no-beautify
6159
values from 1 ... to 1.9999999999 become 1
6260
values from 2 ... to 2.9999999999 become 2
6361
values from 3 ... to 3.9999999999 become 3
6462
```
6563

66-
All intervals have the same length, making the final distribution uniform.
64+
لدى جميع الفترات الطول ذاته مما يجعل التوزيع النهائي موحدًا.

0 commit comments

Comments
 (0)