Skip to content

Commit be35082

Browse files
ooooooArvinH
andauthoredApr 30, 2020
Feature/1 js 05 data type 03 string (#89)
* feat:: en/ch: update article: # Strings 字串 ~ ## Special characters 特殊的角色. * debug:: en/ch: update article: # Strings 字串 ~ ## Special characters 特殊的角色:: 反斜槓簡體字、錯標點、翻譯 * feat:: en/ch: update article: # String length 字串長度 ~ ## Accessing characters 訪問字元 * debug:: en/ch: update article: # String 字串 ~ ## Special characters 特殊的角色:: 翻句通順... 對照檢體檢視 * feat:: en/ch: ## Strings are immutable 字符串不可變 * dbug:: en/ch: ## Quotes 引號:: 翻譯通順 * feat:: en/ch: ## Changing the case 改變大小寫~#### The bitwise NOT trick 按位(bitwise)NOT 技巧 * feat:: en/ch: ### includes, startsWith, endsWith (包含...,用...開始,用...結束) ~ ## Getting a substring 取得一個子字串 * dbug:: en/ch: 翻譯調整 "指定 / 給定" * feat:: en/ch: ## Comparing strings 比對字串 * feat:: en/ch: ### Correct comparisons 正確的比較/ * feat:: en/ch: ## Internals, Unicode 內部結構,Unicode ~ ### Surrogate pairs 代理對 * feat:: en/ch: ### Diacritical marks and normalization 變音標記和標準化/ and 修改 "算法"為"演算法" * feat:: en/ch: ## Summary 總結/ * dbug:: en/ch: "search" 翻譯為 "檢索" * feat:: en/ch: all tasks and solutions * feat:: ch: # 字串(String)~ ## 引號/ * dbug:: ch: 翻譯:古早時代 * dbug:: ch: 翻譯修改 * feat:: ch: ## Special characters 特殊的角色/ * remove english * remove english * 2-check-spam * 3-truncate solution and task remove english * 4-extract-currency/task.md remove english * ### str.indexOf * ## 取得一個子字串 remove english * block ## Comparing strings 比對字串 remove english * fixed words * next ### Diacritical marks and normalization 變音標記和標準化 * remove english, next: ## Summary 總結 * remove english done * fix task importance Co-authored-by: ArvinH <[email protected]>
1 parent dd02efb commit be35082

File tree

8 files changed

+294
-292
lines changed

8 files changed

+294
-292
lines changed
 

‎1-js/05-data-types/03-string/1-ucfirst/solution.md

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
1-
We can't "replace" the first character, because strings in JavaScript are immutable.
1+
我們不能 "替換" 第一個字母,因為 Javascript 的字串是永遠不變的。
22

3-
But we can make a new string based on the existing one, with the uppercased first character:
3+
但我們可以根據已有的字串,創建一個首字母大寫的新字串:
44

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

9-
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.
9+
但仍然有個小問題。若 `str` 為空,則 `str[0]` 會是 `undefined`。而 `undefined` 不會有 `toUpperCase()` 方法,我們會得到錯誤。
1010

11-
There are two variants here:
11+
有兩種處理方式:
1212

13-
1. Use `str.charAt(0)`, as it always returns a string (maybe empty).
14-
2. Add a test for an empty string.
13+
1. 使用 `str.charAt(0)`,它會永遠回傳一個字串 (可能為空) 。
14+
2. 為空字串添加一個測試。
1515

16-
Here's the 2nd variant:
16+
這是第二個作法:
1717

1818
```js run demo
1919
function ucFirst(str) {

‎1-js/05-data-types/03-string/1-ucfirst/task.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ importance: 5
22

33
---
44

5-
# Uppercase the first character
5+
# 首字母大寫
66

7-
Write a function `ucFirst(str)` that returns the string `str` with the uppercased first character, for instance:
7+
寫一個函式 `ucFirst(str)` ,它會將字串 `str` 回傳為首字母大寫的字串,例如:
88

99
```js
1010
ucFirst("john") == "John";

‎1-js/05-data-types/03-string/2-check-spam/solution.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
To make the search case-insensitive, let's bring the string to lower case and then search:
1+
為了使檢索不區分大小寫,我們將字串都改為小寫再檢索:
22

33
```js run demo
44
function checkSpam(str) {

‎1-js/05-data-types/03-string/2-check-spam/task.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ importance: 5
22

33
---
44

5-
# Check for spam
5+
# Check for spam 檢查 spam
66

7-
Write a function `checkSpam(str)` that returns `true` if `str` contains 'viagra' or 'XXX', otherwise `false`.
7+
寫一個函式 `checkSpam(str)` `str` 包含 'vaigra' 或者 'XXX' 回傳 `true`,否則回傳 `false`
88

9-
The function must be case-insensitive:
9+
此函式必須是不區分大小寫:
1010

1111
```js
1212
checkSpam('buy ViAgRA now') == true

‎1-js/05-data-types/03-string/3-truncate/solution.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
The maximal length must be `maxlength`, so we need to cut it a little shorter, to give space for the ellipsis.
1+
最大的長度必須是 `maxlength`,因此我們需將其剪短一點,為省略號留岀空間。
22

3-
Note that there is actually a single unicode character for an ellipsis. That's not three dots.
3+
注意,省略號實際上是一個單獨的 unicode 字元,那不是三個點。
44

55
```js run demo
66
function truncate(str, maxlength) {

‎1-js/05-data-types/03-string/3-truncate/task.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
importance: 5
1+
importance5
22

33
---
44

5-
# Truncate the text
5+
# 截斷文字
66

7-
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`.
7+
建立一個函式 `truncate(str, maxlength)`,它可以檢查該傳入字串 `str` 的長度,且若超過 `maxlength` -- 替換 `str` 結尾為省略號字元 `"..."`,使它的長度等於 `maxlength`
88

9-
The result of the function should be the truncated (if needed) string.
9+
函式的結果應該是被截斷(如果有需要)的字串。
1010

11-
For instance:
11+
例如:
1212

1313
```js
1414
truncate("What I'd like to tell on this topic is:", 20) = "What I'd like to te…"

‎1-js/05-data-types/03-string/4-extract-currency/task.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@ importance: 4
22

33
---
44

5-
# Extract the money
5+
# 提取貨幣
66

7-
We have a cost in the form `"$120"`. That is: the dollar sign goes first, and then the number.
7+
我們以 `"$120"` 格式表示一個費用。即:首先為貨幣符號,然後是數字。
88

9-
Create a function `extractCurrencyValue(str)` that would extract the numeric value from such string and return it.
9+
建立一個函式 `extractCurrencyValue(str)` 它將從這樣一個字串中,提取此數字的值,並回傳它。
1010

11-
The example:
11+
一個例子:
1212

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

‎1-js/05-data-types/03-string/article.md

+270-268
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)
Please sign in to comment.