Skip to content
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
14 changes: 7 additions & 7 deletions 1-js/05-data-types/07-map-set/01-array-unique-map/task.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@ importance: 5

---

# Filter unique array members
# اعداد یکتای آرایه را جداسازی کنید

Let `arr` be an array.
فرض کنیم `arr` یک آرایه باشد.

Create a function `unique(arr)` that should return an array with unique items of `arr`.
تابع `unique(arr)` را بسازید که باید آرایه‌ای شامل المان‌های خاص `arr` را برگرداند.

For instance:
برای مثال:

```js
function unique(arr) {
/* your code */
/* کد شما */
}

let values = ["Hare", "Krishna", "Hare", "Krishna",
Expand All @@ -22,6 +22,6 @@ let values = ["Hare", "Krishna", "Hare", "Krishna",
alert( unique(values) ); // Hare, Krishna, :-O
```

P.S. Here strings are used, but can be values of any type.
پی‌نوشت: اینجا رشته‌ها استفاده شده‌اند اما می‌توانند هر مقداری از هر نوعی باشند.

P.P.S. Use `Set` to store unique values.
پی‌نوشت دوم: از `Set` برای ذخیره مقدارهای یکتا استفاده کنید.
24 changes: 12 additions & 12 deletions 1-js/05-data-types/07-map-set/02-filter-anagrams/solution.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
To find all anagrams, let's split every word to letters and sort them. When letter-sorted, all anagrams are same.
برای پیدا کردن واروواژه‌ها، بیایید هر کلمه را به حروف آن تقسیم کنیم و مرتبش کنیم. زمانی که حروف مرتب شوند، تمام واروواژه‌ها یکسان هستند.

For instance:
برای مثال:

```
nap, pan -> anp
Expand All @@ -9,14 +9,14 @@ cheaters, hectares, teachers -> aceehrst
...
```

We'll use the letter-sorted variants as map keys to store only one value per each key:
ما از کلمه‌هایی که حروف آنها مرتب شده‌اند به عنوان کلید map استفاده می‌کنیم تا فقط یک مقدار را به ازای یک کلید ذخیره کنیم:

```js run
function aclean(arr) {
let map = new Map();

for (let word of arr) {
// split the word by letters, sort them and join back
// کلمه را به حروف آن تقسیم می‌کنیم، آنها را مرتب می‌کنیم و به یکدیگر متصل می‌کنیم
*!*
let sorted = word.toLowerCase().split('').sort().join(''); // (*)
*/!*
Expand All @@ -31,9 +31,9 @@ let arr = ["nap", "teachers", "cheaters", "PAN", "ear", "era", "hectares"];
alert( aclean(arr) );
```

Letter-sorting is done by the chain of calls in the line `(*)`.
ترتیب‌بندی حروف با زنجیره‌ای از فراخوانی‌ها در خط `(*)` انجام می‌شود.

For convenience let's split it into multiple lines:
برای اینکه بهتر شود بیایید آن را به چندین خط تقسیم کنیم:

```js
let sorted = word // PAN
Expand All @@ -43,21 +43,21 @@ let sorted = word // PAN
.join(''); // anp
```

Two different words `'PAN'` and `'nap'` receive the same letter-sorted form `'anp'`.
دو کلمه متفاوت `'PAN'` و `'nap'` کلمه یکسان `'anp'` که حروف آن مرتب شده است را دریافت می‌کنند.

The next line put the word into the map:
خط بعدی کلمه را درون map قرار می‌دهد:

```js
map.set(sorted, word);
```

If we ever meet a word the same letter-sorted form again, then it would overwrite the previous value with the same key in the map. So we'll always have at maximum one word per letter-form.
اگر ما هر زمانی دوباره کلمه‌ای با شکل یکسانی از حروف مرتب شده آن را ببینیم، سپس جایگزین مقدار قبلی می‌شود که کلید یکسانی در map دارد. پس ما همیشه حداکثر یک کلمه به ازای شکل مرتب شده آن داریم.

At the end `Array.from(map.values())` takes an iterable over map values (we don't need keys in the result) and returns an array of them.
در پایان `Array.from(map.values())` یک حلقه‌پذیر از مقدارهای map دریافت می‌کند (ما به کلیدها در نتیجه احتیاجی نداریم) و یک آرایه از آنها برمی‌گرداند.

Here we could also use a plain object instead of the `Map`, because keys are strings.
اینجا ما می‌توانستیم به جای `Map` از شیء ساده هم استفاده کنیم چون کلیدها رشته هستند.

That's how the solution can look:
راه حل ما اینگونه به نظر می‌رسد:

```js run
function aclean(arr) {
Expand Down
15 changes: 7 additions & 8 deletions 1-js/05-data-types/07-map-set/02-filter-anagrams/task.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,26 @@ importance: 4

---

# Filter anagrams
# واروواژه‌ها را جداسازی کنید

[Anagrams](https://en.wikipedia.org/wiki/Anagram) are words that have the same number of same letters, but in different order.
[واروواژه‌ها](https://fa.wikipedia.org/wiki/واروواژه) کلمه‌هایی هستند که تعداد برابری از حروف یکسان دارند، اما با ترتیبی متفاوت.

For instance:
برای مثال:

```
nap - pan
ear - are - era
cheaters - hectares - teachers
```

Write a function `aclean(arr)` that returns an array cleaned from anagrams.
یک تابع `aclean(arr)` بنویسید که آرایه‌ای تهی از واروواژه‌ها را برمی‌گرداند.

For instance:
برای مثال:

```js
let arr = ["nap", "teachers", "cheaters", "PAN", "ear", "era", "hectares"];

alert( aclean(arr) ); // "nap,teachers,ear" or "PAN,cheaters,era"
alert( aclean(arr) ); // "nap,teachers,ear" یا "PAN,cheaters,era"
```

From every anagram group should remain only one word, no matter which one.

از هر گروه واروواژه باید تنها یک کلمه بماند، مهم نیست کدام باشد.
4 changes: 2 additions & 2 deletions 1-js/05-data-types/07-map-set/03-iterable-keys/solution.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

That's because `map.keys()` returns an iterable, but not an array.
دلیلش این است که `map.keys()` یک حلقه‌پذیر را برمی‌گرداند نه یک آرایه.

We can convert it into an array using `Array.from`:
ما می‌توانیم با استفاده از `Array.from` آن را به آرایه تبدیل کنیم:


```js run
Expand Down
8 changes: 4 additions & 4 deletions 1-js/05-data-types/07-map-set/03-iterable-keys/task.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ importance: 5

---

# Iterable keys
# کلیدهای حلقه‌پذیر

We'd like to get an array of `map.keys()` in a variable and then apply array-specific methods to it, e.g. `.push`.
ما می‌خواهیم یک آرایه از `map.keys()` را دورن یک متغیر دیافت کنیم و سپس متدهای مخصوص آرایه را روی آن اعمال کنیم مانند `.push`.

But that doesn't work:
اما کار نمی‌کند:

```js run
let map = new Map();
Expand All @@ -21,4 +21,4 @@ keys.push("more");
*/!*
```

Why? How can we fix the code to make `keys.push` work?
چرا؟ چگونه می‌توانیم کد را درست کنیم تا `keys.push` کار کند؟
Loading