Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Strings#188

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
ImVietnam wants to merge15 commits intojavascript-tutorial:master
base:master
Choose a base branch
Loading
fromImVietnam:patch-13
Open
Show file tree
Hide file tree
Changes fromall commits
Commits
Show all changes
15 commits
Select commitHold shift + click to select a range
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 deletions1-js/05-data-types/03-string/1-ucfirst/solution.md
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
We can't "replace" the first character, because strings inJavaScriptare immutable.
Chúng ta không thể "thay thế" ký tự đầu tiên, bởi vì các chuỗi trongJavaScriptlà bất biến.

But we can make a new string based on the existing one, with the uppercased first character:
Nhưng chúng ta có thể tạo một chuỗi mới dựa trên chuỗi hiện có, với ký tự đầu tiên được viết hoa:

```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.
Có một vấn đề nhỏ mặc dù. Nếu `str`trống, thì `str[0]` `undefined` và vì `undefined`không có phương thức`toUpperCase()`nên chúng ta sẽ gặp lỗi.

There are two variants here:
Có hai biến thể ở đây:

1.Use`str.charAt(0)`,as it always returns a string (maybe empty).
2.Add a test for an empty string.
1.Sử dụng`str.charAt(0)`,vì nó luôn trả về một chuỗi (có thể trống).
2.Thêm kiểm tra cho chuỗi trống.

Here's the 2nd variant:
Đây là biến thể thứ 2:

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

---

#Uppercase the first character
#Chữ hoa ký tự đầu tiên

Write a function`ucFirst(str)`that returns the string`str`with the uppercased first character, for instance:
Ví dụ, viết hàm`ucFirst(str)`trả về chuỗi`str`với ký tự đầu tiên được viết hoa:

```js
ucFirst("john") == "John";
Expand Down
2 changes: 1 addition & 1 deletion1-js/05-data-types/03-string/2-check-spam/solution.md
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
To make the search case-insensitive, let's bring the string to lower case and then search:
Để làm cho tìm kiếm không phân biệt chữ hoa chữ thường, hãy chuyển chuỗi thành chữ thường và sau đó tìm kiếm:

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

---

#Check for spam
#Kiểm tra spam

Write a function`checkSpam(str)`that returns `true`if `str`contains 'viagra'or 'XXX',otherwise `false`.
Viết hàm`checkSpam(str)`trả về `true`nếu `str`chứa 'viagra'hoặc 'XXX',nếu không thì `false`.

The function must be case-insensitive:
Hàm phải phân biệt chữ hoa chữ thường:

```js
checkSpam('buy ViAgRA now') == true
Expand Down
4 changes: 2 additions & 2 deletions1-js/05-data-types/03-string/3-truncate/solution.md
View file
Open in desktop
Original file line numberDiff line numberDiff 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.
Độ dài tối đa phải là`maxlength`,vì vậy chúng ta cần cắt nó ngắn hơn một chút để tạo khoảng trống cho dấu chấm lửng.

Note that there is actually a singleUnicodecharacter for an ellipsis. That's not three dots.
Lưu ý rằng thực tế có một ký tựUnicodeduy nhất cho dấu chấm lửng. Đó không phải là ba chấm.

```js run demo
function truncate(str, maxlength) {
Expand Down
8 changes: 4 additions & 4 deletions1-js/05-data-types/03-string/3-truncate/task.md
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -2,13 +2,13 @@ importance: 5

---

#Truncate the text
#Cắt bớt văn bản

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`.
Tạo một hàm `truncate(str, maxlength)`để kiểm tra độ dài của `str`và, nếu nó vượt quá`maxlength` --thay thế phần cuối của`str`bằng ký tự dấu chấm lửng`"…"`,để tạo chiều dài bằng `maxlength`.

The result of the function should be the truncated (if needed) string.
Kết quả của hàm phải là chuỗi bị cắt ngắn (nếu cần).

For instance:
Ví dụ:

```js
truncate("What I'd like to tell on this topic is:", 20) = "What I'd like to te…"
Expand Down
8 changes: 4 additions & 4 deletions1-js/05-data-types/03-string/4-extract-currency/task.md
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -2,13 +2,13 @@ importance: 4

---

#Extract the money
#Trích xuất tiền

We have a cost in the form `"$120"`.That is: the dollar sign goes first, and then the number.
Chúng ta có chi phí ở dạng `"$120"`.Đó là: ký hiệu đô la đi trước, sau đó là số.

Create a function `extractCurrencyValue(str)`that would extract the numeric value from such string and return it.
Tạo một hàm `extractCurrencyValue(str)`sẽ trích xuất giá trị số từ chuỗi đó và trả về giá trị đó.

The example:
Ví dụ:

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

[8]ページ先頭

©2009-2025 Movatter.jp