Skip to content

Feature/1 js 05 data type 03 string #89

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
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
691007c
feat:: en/ch: update article: # Strings 字串 ~ ## Special characters 特殊…
oooooo Nov 16, 2019
2698b42
debug:: en/ch: update article: # Strings 字串 ~ ## Special characters 特…
oooooo Nov 16, 2019
6dbc6a3
feat:: en/ch: update article: # String length 字串長度 ~ ## Accessing cha…
oooooo Nov 17, 2019
fa8294c
debug:: en/ch: update article: # String 字串 ~ ## Special characters 特殊…
oooooo Nov 17, 2019
ef8ee20
feat:: en/ch: ## Strings are immutable 字符串不可變
oooooo Nov 18, 2019
003d8e4
dbug:: en/ch: ## Quotes 引號:: 翻譯通順
oooooo Nov 18, 2019
f1c8407
feat:: en/ch: ## Changing the case 改變大小寫~#### The bitwise NOT trick 按…
oooooo Nov 20, 2019
63cb49e
feat:: en/ch: ### includes, startsWith, endsWith (包含...,用...開始,用...結束…
oooooo Nov 23, 2019
b1a8c3d
dbug:: en/ch: 翻譯調整 "指定 / 給定"
oooooo Nov 23, 2019
93a42e6
feat:: en/ch: ## Comparing strings 比對字串
oooooo Nov 23, 2019
3c974cd
feat:: en/ch: ### Correct comparisons 正確的比較/
oooooo Nov 25, 2019
43387dd
feat:: en/ch: ## Internals, Unicode 內部結構,Unicode ~ ### Surrogate pair…
oooooo Nov 26, 2019
e113de0
feat:: en/ch: ### Diacritical marks and normalization 變音標記和標準化/ and 修…
oooooo Nov 27, 2019
4133378
feat:: en/ch: ## Summary 總結/
oooooo Nov 28, 2019
1ab25bc
dbug:: en/ch: "search" 翻譯為 "檢索"
oooooo Dec 1, 2019
6178acb
feat:: en/ch: all tasks and solutions
oooooo Dec 1, 2019
0ffa06a
feat:: ch: # 字串(String)~ ## 引號/
oooooo Dec 1, 2019
6d28b2f
dbug:: ch: 翻譯:古早時代
oooooo Dec 1, 2019
3b70954
dbug:: ch: 翻譯修改
oooooo Dec 9, 2019
afc7c52
feat:: ch: ## Special characters 特殊的角色/
oooooo Dec 9, 2019
14948cb
remove english
oooooo Mar 11, 2020
c070168
remove english
oooooo Mar 11, 2020
dfdd416
2-check-spam
oooooo Mar 11, 2020
5db9108
3-truncate solution and task remove english
oooooo Mar 11, 2020
19160df
4-extract-currency/task.md remove english
oooooo Mar 11, 2020
bcd9b66
### str.indexOf
oooooo Mar 11, 2020
f83d82c
## 取得一個子字串 remove english
oooooo Mar 11, 2020
f9d60c3
block ## Comparing strings 比對字串 remove english
oooooo Mar 11, 2020
8cc17e5
fixed words
oooooo Mar 11, 2020
c8bea8b
next ### Diacritical marks and normalization 變音標記和標準化
oooooo Mar 12, 2020
f6ea773
remove english, next: ## Summary 總結
oooooo Mar 20, 2020
d39f8e1
remove english done
oooooo Mar 20, 2020
5c3bc04
fix task importance
oooooo Mar 20, 2020
fb3a379
Merge branch 'master' into feature/1_js-05_data_type-03_string
ArvinH Apr 29, 2020
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.
我們不能 "替換" 第一個字母,因為 Javascript 的字串是永遠不變的。

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
# Check for spam 檢查 spam

Write a function `checkSpam(str)` that returns `true` if `str` contains 'viagra' or 'XXX', otherwise `false`.
寫一個函式 `checkSpam(str)` 若 `str` 包含 'vaigra' 或者 '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 demo
function truncate(str, maxlength) {
Expand Down
10 changes: 5 additions & 5 deletions 1-js/05-data-types/03-string/3-truncate/task.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
importance: 5
importance5

---

# 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
8 changes: 4 additions & 4 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,13 +2,13 @@ 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
Expand Down
Loading