Skip to content

Commit de41da9

Browse files
authored
Merge pull request #33 from yehiafouda/array
array translation
2 parents 6a47c6f + 9b753cd commit de41da9

File tree

11 files changed

+260
-270
lines changed

11 files changed

+260
-270
lines changed
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
1-
The result is `4`:
1+
`4`:الناتج
22

33

44
```js run
5-
let fruits = ["Apples", "Pear", "Orange"];
5+
let fruits = ["البرتقال", "الكمثري", "التفاح"];
66

77
let shoppingCart = fruits;
88

9-
shoppingCart.push("Banana");
9+
shoppingCart.push("الموز");
1010

1111
*!*
1212
alert( fruits.length ); // 4
1313
*/!*
1414
```
1515

16-
That's because arrays are objects. So both `shoppingCart` and `fruits` are the references to the same array.
16+
هذا لان المصفوفات تعتبر كائنات. لذا كلا من `shoppingCart` و `fruits` يعدوا كمرجع لنفس المصفوفه.
1717

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

33
---
44

5-
# Is array copied?
5+
# هل تم نسخ المصفوفه؟
66

7-
What is this code going to show?
7+
ماالذي سوف يعرضه الكود؟
88

99
```js
10-
let fruits = ["Apples", "Pear", "Orange"];
10+
let fruits = ["البرتقال", "الكمثري", "التفاح"];
1111

12-
// push a new value into the "copy"
12+
// "ادفع قيمه جديده داخل"النسخ
1313
let shoppingCart = fruits;
14-
shoppingCart.push("Banana");
14+
shoppingCart.push("الموز");
1515

16-
// what's in fruits?
16+
//؟ fruits ماالذي داخل
1717
alert( fruits.length ); // ?
1818
```
1919

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,43 @@
1-
# Slow solution
1+
# الحل الأبطئ
22

3-
We can calculate all possible subsums.
3+
يمكننا حساب جميع الفئات الفرعية الممكنة.
44

5-
The simplest way is to take every element and calculate sums of all subarrays starting from it.
5+
إن أبسط طريقة هي أخذ كل عنصر وحساب جميع المصفوفات الفرعية بدءًا منها.
66

7-
For instance, for `[-1, 2, 3, -9, 11]`:
7+
علي سبيل المثال, for `[-1, 2, 3, -9, 11]`:
88

99
```js no-beautify
10-
// Starting from -1:
10+
// البدء من -1:
1111
-1
1212
-1 + 2
1313
-1 + 2 + 3
1414
-1 + 2 + 3 + (-9)
1515
-1 + 2 + 3 + (-9) + 11
1616

17-
// Starting from 2:
17+
// البدء من 2:
1818
2
1919
2 + 3
2020
2 + 3 + (-9)
2121
2 + 3 + (-9) + 11
2222

23-
// Starting from 3:
23+
// البدء من 3:
2424
3
2525
3 + (-9)
2626
3 + (-9) + 11
2727

28-
// Starting from -9
28+
// البدء من -9
2929
-9
3030
-9 + 11
3131

32-
// Starting from 11
32+
// البدء من 11
3333
11
3434
```
3535

36-
The code is actually a nested loop: the external loop over array elements, and the internal counts subsums starting with the current element.
36+
الكود هو في الواقع حلقة متداخلة: الحلقة الخارجية فوق عناصر المصفوفه ، والعد الداخلي يحسب الفئات الفرعية التي تبدأ بالعنصر الحالي.
3737

3838
```js run
3939
function getMaxSubSum(arr) {
40-
let maxSum = 0; // if we take no elements, zero will be returned
40+
let maxSum = 0; // إذا لم نأخذ أي عناصر ، فسيتم إرجاع الصفر
4141

4242
for (let i = 0; i < arr.length; i++) {
4343
let sumFixedStart = 0;
@@ -57,25 +57,24 @@ alert( getMaxSubSum([1, 2, 3]) ); // 6
5757
alert( getMaxSubSum([100, -9, 2, -3, 5]) ); // 100
5858
```
5959

60-
The solution has a time complexety of [O(n<sup>2</sup>)](https://en.wikipedia.org/wiki/Big_O_notation). In other words, if we increase the array size 2 times, the algorithm will work 4 times longer.
60+
الحل له تعقيد زمني [O(n<sup>2</sup>)](https://en.wikipedia.org/wiki/Big_O_notation). بمعنى آخر ، إذا قمنا بزيادة حجم المصفوفه مرتين ، فستعمل الخوارزمية لفترة أطول 4 مرات.
61+
بالنسبة للمصفوفات الكبيرة (1000 أو 10000 أو أكثر من العناصر) ، يمكن أن تؤدي هذه الخوارزميات إلى بطء خطير.
6162

62-
For big arrays (1000, 10000 or more items) such algorithms can lead to a serious sluggishness.
63+
# الحل الأسرع
6364

64-
# Fast solution
65+
دعنا نسير في المصفوفة ونحتفظ بالمجموع الجزئي الحالي للعناصر في المتغير `s`. إذا أصبحت `s` سالبة في وقت ما ، قم بتعيين` s = 0`. سيكون الحد الأقصى لكل هذه الإجابات هو الإجابة.
6566

66-
Let's walk the array and keep the current partial sum of elements in the variable `s`. If `s` becomes negative at some point, then assign `s=0`. The maximum of all such `s` will be the answer.
67-
68-
If the description is too vague, please see the code, it's short enough:
67+
إذا كان الوصف غامضًا جدًا ، فيرجى الاطلاع على الكود ، فهو قصير بما يكفي:
6968

7069
```js run demo
7170
function getMaxSubSum(arr) {
7271
let maxSum = 0;
7372
let partialSum = 0;
7473

75-
for (let item of arr) { // for each item of arr
76-
partialSum += item; // add it to partialSum
77-
maxSum = Math.max(maxSum, partialSum); // remember the maximum
78-
if (partialSum < 0) partialSum = 0; // zero if negative
74+
for (let item of arr) { // لكل عنصر في المصفوفه
75+
partialSum += item; // أضفه إلى مجموع الجزئي
76+
maxSum = Math.max(maxSum, partialSum); // تذكر الحد الأقصى
77+
if (partialSum < 0) partialSum = 0; // صفر إذا كانت سلبية
7978
}
8079

8180
return maxSum;
@@ -89,6 +88,6 @@ alert( getMaxSubSum([1, 2, 3]) ); // 6
8988
alert( getMaxSubSum([-1, -2, -3]) ); // 0
9089
```
9190

92-
The algorithm requires exactly 1 array pass, so the time complexity is O(n).
91+
تتطلب الخوارزمية تمريراً مصفوفه واحده ، لذا فإن تعقيد الوقت هو O (n).
9392

94-
You can find more detail information about the algorithm here: [Maximum subarray problem](http://en.wikipedia.org/wiki/Maximum_subarray_problem). If it's still not obvious why that works, then please trace the algorithm on the examples above, see how it works, that's better than any words.
93+
يمكنك العثور على مزيد من المعلومات التفصيلية حول الخوارزمية هنا: [Maximum subarray problem](http://en.wikipedia.org/wiki/Maximum_subarray_problem). إذا كان لا يزال من غير الواضح سبب نجاح ذلك ، فالرجاء تتبع الخوارزمية في الأمثلة أعلاه ، ومعرفة كيفية عملها ، وهذا أفضل من أي كلمات.
Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,30 @@
1-
importance: 2
1+
الأهميه: 2
22

33
---
44

5-
# A maximal subarray
5+
# مجموعة فرعية قصوى
66

7-
The input is an array of numbers, e.g. `arr = [1, -2, 3, 4, -9, 6]`.
7+
الإدخال هو مصفوفة من الأرقام ، على سبيل المثال `arr = [1, -2, 3, 4, -9, 6]`.
88

9-
The task is: find the contiguous subarray of `arr` with the maximal sum of items.
9+
المهمة هي: العثور على مصفوفة متجاورة من `arr` مع العدد الأقصى للعناصر.
1010

11-
Write the function `getMaxSubSum(arr)` that will return that sum.
11+
اكتب الداله `getMaxSubSum(arr)` التي سوف تعيد الجمع.
1212

13-
For instance:
13+
علي سبيل المثال:
1414

1515
```js
16-
getMaxSubSum([-1, *!*2, 3*/!*, -9]) == 5 (the sum of highlighted items)
16+
getMaxSubSum([-1, *!*2, 3*/!*, -9]) == 5 (مجموع العناصر المميزة)
1717
getMaxSubSum([*!*2, -1, 2, 3*/!*, -9]) == 6
1818
getMaxSubSum([-1, 2, 3, -9, *!*11*/!*]) == 11
1919
getMaxSubSum([-2, -1, *!*1, 2*/!*]) == 3
2020
getMaxSubSum([*!*100*/!*, -9, 2, -3, 5]) == 100
21-
getMaxSubSum([*!*1, 2, 3*/!*]) == 6 (take all)
21+
getMaxSubSum([*!*1, 2, 3*/!*]) == 6 (خذها كلها)
2222
```
2323

24-
If all items are negative, it means that we take none (the subarray is empty), so the sum is zero:
24+
إذا كانت جميع العناصر سالبة ، فهذا يعني أننا لا نأخذ أي منها (المصفوفة فارغة) ، لذا يكون المجموع صفرًا:
2525

2626
```js
2727
getMaxSubSum([-1, -2, -3]) = 0
2828
```
2929

30-
Please try to think of a fast solution: [O(n<sup>2</sup>)](https://en.wikipedia.org/wiki/Big_O_notation) or even O(n) if you can.
30+
من فضلك فكر في أسرع حل: [O(n<sup>2</sup>)](https://en.wikipedia.org/wiki/Big_O_notation) أو حتى O (n) إذا استطعت.
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11

22

33
```js run
4-
let styles = ["Jazz", "Blues"];
5-
styles.push("Rock-n-Roll");
6-
styles[Math.floor((styles.length - 1) / 2)] = "Classics";
4+
let styles = ["البلوز", "موسيقي الجاز"];
5+
styles.push("موسيقى الروك آند رول");
6+
styles[Math.floor((styles.length - 1) / 2)] = "كلاسيكيات";
77
alert( styles.shift() );
8-
styles.unshift("Rap", "Reggae");
8+
styles.unshift("موسيقي الريغي", "موسيقى الراب");
99
```
1010

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,23 @@
1-
importance: 5
1+
الاهميه: 5
22

33
---
44

5-
# Array operations.
5+
# معاملات المصفوفه.
66

7-
Let's try 5 array operations.
7+
هيا نجرب 5 معاملات للمصفوفه.
88

9-
1. Create an array `styles` with items "Jazz" and "Blues".
10-
2. Append "Rock-n-Roll" to the end.
11-
3. Replace the value in the middle by "Classics". Your code for finding the middle value should work for any arrays with odd length.
12-
4. Strip off the first value of the array and show it.
13-
5. Prepend `Rap` and `Reggae` to the array.
14-
15-
The array in the process:
9+
1. قم بانشاء عده عناصر `styles` "موسيقي الجاز" و "البلوز" .
10+
2. اضف في النهايه" موسيقي الروك آند رول"
11+
3. استبدل القيمة في المنتصف بـ "كلاسيكيات". يجب ان يعمل الكود الخاص بك للعثور على القيمة الوسطى لأي مصفوفه ذات طول فردي.
12+
4. تجريد القيمة الأولى من مصفوفه وإظهارها.
13+
5. استعد `Rap` و `Reggae` الي المصفوفه .
1614

15+
المصفوفه في العمليه :
1716
```js no-beautify
18-
Jazz, Blues
19-
Jazz, Blues, Rock-n-Roll
20-
Jazz, Classics, Rock-n-Roll
21-
Classics, Rock-n-Roll
22-
Rap, Reggae, Classics, Rock-n-Roll
17+
موسيقي الجاز, البلوز
18+
موسيقي الجاز, البلوز, موسيقى الروك آند رول
19+
موسيقي الجاز, كلاسيكيات, موسيقى الروك آند رول
20+
كلاسيكيات,موسيقى الروك آند رول
21+
موسيقى الراب, موسيقي الريغي, كلاسيكيات, موسيقى الروك آند رول
2322
```
2423

1-js/05-data-types/04-array/3-call-array-this/solution.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
The call `arr[2]()` is syntactically the good old `obj[method]()`, in the role of `obj` we have `arr`, and in the role of `method` we have `2`.
1+
استدعاء `()arr[2]` نحويا هو اسلوب جيد `()obj[method]`, في دور `obj` نحن لدينا `arr`, وفي دور `method`نحن لدينا `2`.
22

3-
So we have a call of the function `arr[2]` as an object method. Naturally, it receives `this` referencing the object `arr` and outputs the array:
3+
لذلك لدينا استدعاء للدالة `arr [2]` كطريقة كائن. وبطبيعة الحال ، فإنه يتلقى `this` يشير إلى الكائن` arr` ويخرج المصفوفه:
44

55
```js run
66
let arr = ["a", "b"];
@@ -12,4 +12,4 @@ arr.push(function() {
1212
arr[2](); // a,b,function(){...}
1313
```
1414

15-
The array has 3 values: initially it had two, plus the function.
15+
المصفوفة لها 3 قيم: في البداية كانت تحتوي على قيمتين ، بالإضافة إلى function.

1-js/05-data-types/04-array/3-call-array-this/task.md

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

33
---
44

5-
# Calling in an array context
5+
# استدعاء في سياق مصفوفه
66

7-
What is the result? Why?
7+
ماهي النتيجه؟ لماذا؟
88

99
```js
1010
let arr = ["a", "b"];

1-js/05-data-types/04-array/5-array-input-sum/solution.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Please note the subtle, but important detail of the solution. We don't convert `value` to number instantly after `prompt`, because after `value = +value` we would not be able to tell an empty string (stop sign) from the zero (valid number). We do it later instead.
1+
يرجى ملاحظة التفاصيل الدقيقة والمهمة للحل. نحن لا نقوم بتحويل`value` الي رقم فورا بعد `prompt`, لان بعد القيمه `value = +value` لن نتمكن من معرفة النص فارغ (علامة التوقف) من الصفر (رقم صالح). سنقوم بذلك لاحقًا بدلاً من ذلك.
22

33

44
```js run demo
@@ -8,9 +8,9 @@ function sumInput() {
88

99
while (true) {
1010

11-
let value = prompt("A number please?", 0);
11+
let value = prompt(" رقم من فضلك A Number Please", 0);
1212

13-
// should we cancel?
13+
// يجب أن نلغي؟
1414
if (value === "" || value === null || !isFinite(value)) break;
1515

1616
numbers.push(+value);
Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
importance: 4
1+
الاهميه: 4
22

33
---
44

5-
# Sum input numbers
5+
# اجمع الارقام المدخله
66

7-
Write the function `sumInput()` that:
7+
اكتب الداله `sumInput()` التي:
88

9-
- Asks the user for values using `prompt` and stores the values in the array.
10-
- Finishes asking when the user enters a non-numeric value, an empty string, or presses "Cancel".
11-
- Calculates and returns the sum of array items.
9+
- اطلب من المستخدم القيم باستخدام `prompt` وتخزين تلك القيم داخل المصفوفه.
10+
- قم بإنهاء الاسئله عندما يدخل المستخدم قيمه غير رقمي او نص فارغ او بضغط علي "انهاء"
11+
- احسب وقم بإعاده عمليه الجمع لعناصر المصفوفه.
1212

13-
P.S. A zero `0` is a valid number, please don't stop the input on zero.
13+
ملاحظة. الصفر `0` هو رقم صالح ، يرجى عدم إيقاف الإدخال على الصفر.
1414

1515
[demo]

0 commit comments

Comments
 (0)