Skip to content

Strings #128

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

Merged
merged 29 commits into from
Jun 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
0d0c1b3
Translate a part of article
mahdiHash Jun 1, 2021
e637c6f
Translate a part of article
mahdiHash Jun 1, 2021
a46f621
Translate a part of article
mahdiHash Jun 2, 2021
ba80026
Translate a part of article
mahdiHash Jun 3, 2021
2bacf77
Translate a part of article
mahdiHash Jun 4, 2021
9b447bd
Translate a part of article
mahdiHash Jun 4, 2021
8fd420e
Change a line for better translation
mahdiHash Jun 4, 2021
15a81eb
Translate a part of article
mahdiHash Jun 5, 2021
3c08543
Translate a part of article
mahdiHash Jun 6, 2021
e1ec611
Merge branch 'javascript-tutorial:master' into master
mahdiHash Jun 6, 2021
3662be1
Translate a part of article
mahdiHash Jun 7, 2021
506a568
Translate a part of article
mahdiHash Jun 8, 2021
76659c8
Translate a part of article
mahdiHash Jun 9, 2021
a05bf64
Remove a line which was not translated
mahdiHash Jun 9, 2021
d07639f
Translate a part of article
mahdiHash Jun 10, 2021
eb6d316
Fix a translation mistake
mahdiHash Jun 10, 2021
600f0a7
Translate a part of article
mahdiHash Jun 11, 2021
973b3b7
Fix a typo
mahdiHash Jun 11, 2021
37bbbc1
Translate a part of article
mahdiHash Jun 12, 2021
9629ab9
Translate a part of article
mahdiHash Jun 13, 2021
fda6d5e
Translate article
mahdiHash Jun 14, 2021
e3f8fa5
Translate task of "ucfirst"
mahdiHash Jun 14, 2021
c46bb6e
Translate solution of "ucfirst"
mahdiHash Jun 14, 2021
ee40436
Translate task of "check spam"
mahdiHash Jun 14, 2021
a0de8c4
Translate solution of "check spam"
mahdiHash Jun 14, 2021
ca0edd2
Translate task of "truncate"
mahdiHash Jun 14, 2021
217019e
Translate solution of "truncate"
mahdiHash Jun 14, 2021
db6ce6f
Translate task of "extract currency"
mahdiHash Jun 14, 2021
44a846f
Apply suggestions from code review
mahdiHash Jun 14, 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
14 changes: 7 additions & 7 deletions 1-js/05-data-types/03-string/1-ucfirst/solution.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
We can't "replace" the first character, because strings in JavaScript are immutable.
ما نمی‌توانیم حرف اول را «جایگزین» کنیم، چون رشته‌ها در جاوااسکریپت غیر قابل تغییر هستند.

But we can make a new string based on the existing one, with the uppercased first character:
اما می‌توانیم یک رشته جدید را بر اساس رشته موجود با کاراکتر اول بزرگ شده بسازیم:

```js
let newStr = str[0].toUpperCase() + str.slice(1);
```

There's a small problem though. If `str` is empty, then `str[0]` is `undefined`, and as `undefined` doesn't have the `toUpperCase()` method, we'll get an error.
البته یک مشکل کوچک وجود دارد. اگر `str` خالی باشد، پس `str[0]` برابر با `undefined` است و `undefined` متد `toUpperCase()` را ندارد، پس ما ارور خواهیم داشت.

There are two variants here:
دو روش پیش روی‌مان داریم:

1. Use `str.charAt(0)`, as it always returns a string (maybe empty).
2. Add a test for an empty string.
1. از `str.charAt(0)` استفاده کنیم، چون همیشه یک رشته برمی‌گرداند (شاید رشته خالی).
2. یک تست برای رشته خالی اضافه کنیم.

Here's the 2nd variant:
روش دوم را اینجا داریم:

```js run demo
function ucFirst(str) {
Expand Down
4 changes: 2 additions & 2 deletions 1-js/05-data-types/03-string/1-ucfirst/task.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ importance: 5

---

# Uppercase the first character
# کاراکتر اول را بزرگ کنید

Write a function `ucFirst(str)` that returns the string `str` with the uppercased first character, for instance:
یک تابع `ucFirst(str)` بنویسید که رشته `str` را با حرف اول بزرگ شده برمی‌گرداند، برای مثال:

```js
ucFirst("john") == "John";
Expand Down
2 changes: 1 addition & 1 deletion 1-js/05-data-types/03-string/2-check-spam/solution.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
To make the search case-insensitive, let's bring the string to lower case and then search:
برای اینکه جستجو را به بزرگی یا کوچکی حرف حساس نکنیم، بیایید حروف رشته را کوچک کنیم و سپس جستجو کنیم:

```js run demo
function checkSpam(str) {
Expand Down
6 changes: 3 additions & 3 deletions 1-js/05-data-types/03-string/2-check-spam/task.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ importance: 5

---

# Check for spam
# بررسی هرزنامه

Write a function `checkSpam(str)` that returns `true` if `str` contains 'viagra' or 'XXX', otherwise `false`.
یک تابع `checkSpam(str)` بنویسید که اگر `str` دارای کلمات 'viagra' یا 'XXX' باشد مقدار `true` را برگرداند، در غیر این صورت `false`.

The function must be case-insensitive:
تابع نباید به بزرگی یا کوچکی حرف حساس باشد:

```js
checkSpam('buy ViAgRA now') == true
Expand Down
4 changes: 2 additions & 2 deletions 1-js/05-data-types/03-string/3-truncate/solution.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The maximal length must be `maxlength`, so we need to cut it a little shorter, to give space for the ellipsis.
بیشترین طول باید `maxlength` باشد، پس ما نیاز داریم که آن را کمتر کنیم، تا برای کاراکتر حذف جا باز شود.

Note that there is actually a single Unicode character for an ellipsis. That's not three dots.
در نظر داشته باشید در واقع یک کاراکتر Unicode برای کاراکتر حذف وجود دارد. این کاراکتر سه نقطه نیست.

```js run
function truncate(str, maxlength) {
Expand Down
8 changes: 4 additions & 4 deletions 1-js/05-data-types/03-string/3-truncate/task.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ importance: 5

---

# Truncate the text
# کوتاه کردن متن

Create a function `truncate(str, maxlength)` that checks the length of the `str` and, if it exceeds `maxlength` -- replaces the end of `str` with the ellipsis character `"…"`, to make its length equal to `maxlength`.
یک تابع `truncate(str, maxlength)` بسازید که طول `str` را بررسی می‌کند و اگر از `maxlength` بیشتر باشد، پایان رشته `str` را با کاراکتر حذف `"…"` جایگذاری کند، تا طول آن برابر با `maxlength` شود.

The result of the function should be the truncated (if needed) string.
نتیجه تابع باید رشته کوتاه‌شده باشد (در سورت نیاز).

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

```js
truncate("What I'd like to tell on this topic is:", 20) = "What I'd like to te…"
Expand Down
9 changes: 4 additions & 5 deletions 1-js/05-data-types/03-string/4-extract-currency/task.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@ importance: 4

---

# Extract the money
# استخراج پول

We have a cost in the form `"$120"`. That is: the dollar sign goes first, and then the number.
ما یک قیمت به شکل `"$120"` داریم. به این معنی که علامت دلار اول می‌آید، و سپس عدد.

Create a function `extractCurrencyValue(str)` that would extract the numeric value from such string and return it.
یک تابع `extractCurrencyValue(str)` بسازید که مقدار عددی را از چنین رشته‌ای بیرون می‌کند و آن را برمی‌گرداند.

The example:
مثال:

```js
alert( extractCurrencyValue('$120') === 120 ); // true
```

Loading