Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Recursion and stack #159

Merged
merged 24 commits into from
Oct 5, 2021
Merged
Changes from 1 commit
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
04b8cb2
Translate a part of article
mahdiHash Sep 28, 2021
ed3051b
Translate a part of article
mahdiHash Sep 29, 2021
515ad84
Merge branch 'javascript-tutorial:master' into master
mahdiHash Sep 30, 2021
5fcdd34
Translate a part of article
mahdiHash Sep 30, 2021
17cc7e1
Translate a part of article
mahdiHash Oct 1, 2021
923fc54
Translate a part of article
mahdiHash Oct 1, 2021
5dfd251
Translate a part of article
mahdiHash Oct 2, 2021
b04627a
Translate a part of article
mahdiHash Oct 3, 2021
dccf17d
Translate article
mahdiHash Oct 3, 2021
a0a8673
Translate task of "sum-to"
mahdiHash Oct 4, 2021
43f6242
Translate solution of "sum-to"
mahdiHash Oct 4, 2021
e4568a1
Translate task of "factorial"
mahdiHash Oct 4, 2021
d62d0dc
Translate solution of "factorial"
mahdiHash Oct 4, 2021
a58435c
Translate task of "fibonacci-numbers"
mahdiHash Oct 4, 2021
a453039
Translate solution of "fibonacci-numbers"
mahdiHash Oct 4, 2021
7e5b852
Translate task of "output-single-linked-list"
mahdiHash Oct 4, 2021
a67bd44
Translate solution of "output-single-linked-list"
mahdiHash Oct 4, 2021
aa26bd7
Translate task of "output-single-linked-list-reverse"
mahdiHash Oct 4, 2021
4978f4f
Translate solution of "output-single-linked-list-reverse"
mahdiHash Oct 4, 2021
c4fc445
Apply suggestions from code review
mahdiHash Oct 4, 2021
2ffc9af
Update 1-js/06-advanced-functions/01-recursion/article.md
mahdiHash Oct 4, 2021
c084a25
Change "stack" to "پشته"
mahdiHash Oct 4, 2021
0fe37e7
Change "stack" to "پشته"
mahdiHash Oct 4, 2021
fafd50f
Change "stack" to "پشته"
mahdiHash Oct 4, 2021
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
Prev Previous commit
Next Next commit
Translate article
  • Loading branch information
mahdiHash committed Oct 3, 2021
commit dccf17dbadf746025ddd1859ede889a21419bbf1
18 changes: 9 additions & 9 deletions 1-js/06-advanced-functions/01-recursion/article.md
Original file line number Diff line number Diff line change
Expand Up @@ -520,23 +520,23 @@ list.next = list.next.next;
- همچنین می‌توانیم یک متغیر به نام `tail` که به المان آخر لیست رجوع می‌کند اضافه کنیم (و هر زمان که المانی اضافه/حذف می‌کنیم آن را اپدیت کنیم).
- ...ساختار داده می‌تواند با توجه به نیازهای ما خیلی تنوع داشته باشد.

## Summary
## خلاصه

Terms:
- *Recursion* is a programming term that means calling a function from itself. Recursive functions can be used to solve tasks in elegant ways.
اصطلاحات:
- *بازگشت* یک عبارت برنامه‌نویسی و به معنی فراخوانی یک تابع در خودش است. تابع‌های بازگشتی می‌توانند برای حل کردن مسائل با راه‌هایی عالی استفاده شوند.

When a function calls itself, that's called a *recursion step*. The *basis* of recursion is function arguments that make the task so simple that the function does not make further calls.
زمانی که یک تابع خودش را فراخوانی می‌کند، به آن *مرحله بازگشت* می‌گویند. *اساس* بازگشت، آرگومان‌های تابع هستند که کار را انقدر ساده می‌کنند که تابع دیگر فراخوانی‌های بیشتری انجام نمی‌دهد.

- A [recursively-defined](https://en.wikipedia.org/wiki/Recursive_data_type) data structure is a data structure that can be defined using itself.
- یک ساختار داده که به صورت [بازگشتی تعریف شده باشد](https://en.wikipedia.org/wiki/Recursive_data_type) ساختار داده‌ای است که می‌تواند با استفاده از خودش تعریف شود.

For instance, the linked list can be defined as a data structure consisting of an object referencing a list (or null).
برای مثال، لیست پیوندی می‌تواند به عنوان ساختار داده‌ای تعریف شود که شیءای رجوع‌کننده به یک لیست (یا هیچی) را شامل شود.

```js
list = { value, next -> list }
```

Trees like HTML elements tree or the department tree from this chapter are also naturally recursive: they branch and every branch can have other branches.
درخت‌ها مانند المان‌های HTML یا درخت بخش اداری در این فصل هم به طور طبیعی بازگشتی هستند: آنها شاخه‌شاخه می‌شوند و هر شاخه می‌تواند شاخه‌های دیگر هم داشته باشد.

Recursive functions can be used to walk them as we've seen in the `sumSalary` example.
همانطور که در مثال `sumSalary` دیدیم تابع‌های بازگشتی می‌توانند برای پیمایش درون آنها استفاده شوند.

Any recursive function can be rewritten into an iterative one. And that's sometimes required to optimize stuff. But for many tasks a recursive solution is fast enough and easier to write and support.
هر تابع بازگشتی می‌تواند به صورت تکرارشونده بازنویسی شود. و گاهی اوقات برای بهینه کردن به آن نیاز است. اما برای بسیاری از کارها راه‌حل بازگشتی به اندازه کافی سریع و برای نوشتن و پشتیبانی کردن راحت‌تر است.