chore(i18n,learn): processed translations (#45504)
This commit is contained in:
@ -8,9 +8,9 @@ dashedName: convert-celsius-to-fahrenheit
|
||||
|
||||
# --description--
|
||||
|
||||
將攝氏度轉換爲華氏度的計算方式爲:攝氏度乘以 `9/5` 然後加上 `32`。
|
||||
從攝氏轉換爲華氏的公式是,攝氏溫度乘以 `9/5`,再加上 `32`。
|
||||
|
||||
輸入參數 `celsius` 代表一個攝氏度的溫度。 使用已定義的變量 `fahrenheit`,並賦值爲相應的華氏度的溫度值。 根據上述轉換公式來進行轉換。
|
||||
輸入參數 `celsius` 代表一個攝氏度的溫度。 使用已定義的變量 `fahrenheit`,並賦值爲相應的華氏度的溫度值。 使用上面提到的公式來幫助將攝氏溫度轉換爲華氏溫度。
|
||||
|
||||
# --hints--
|
||||
|
||||
|
@ -19,7 +19,7 @@ users.hasOwnProperty('Alan');
|
||||
|
||||
# --instructions--
|
||||
|
||||
請完善這個函數,如果傳遞給它的對象包含四個名字 `Alan`、`Jeff`、`Sarah` 和 `Ryan`,函數返回 true,否則返回 false。
|
||||
請完善這個函數,如果傳遞給它的對象包含四個名字 `Alan`、`Jeff`、`Sarah` 和 `Ryan`,函數返回 `true`,否則返回 `false`。
|
||||
|
||||
# --hints--
|
||||
|
||||
|
@ -10,7 +10,7 @@ dashedName: remove-items-using-splice
|
||||
|
||||
在之前的挑戰中,我們已經學習瞭如何用 `shift()` 和 `pop()` 從數組的開頭或末尾移除元素。 但如果我們想刪除數組中間的一個元素, 或者想一次刪除多個元素,該如何操作呢? 這時候我們就需要使用 `splice()` 方法了, `splice()` 可以讓我們從數組中的任意位置**連續刪除任意數量的元素**。
|
||||
|
||||
`splice()` 最多可以接受 3 個參數,但現在我們先關注前兩個。 `splice()` 接收的前兩個參數是整數,表示正在調用 的`splice()` 數組中的元素的索引或位置。 別忘了,數組的索引是*從 0 開始的*,所以我們要用 `0` 來表示數組中的第一個元素。 `splice()` 的第一個參數代表從數組中的哪個索引開始移除元素,而第二個參數表示要從數組中的這個位置開始刪除多少個元素。 例如:
|
||||
`splice()` 最多可以接受 3 個參數,但現在我們先關注前兩個。 `splice()` 的前兩個參數是整數,表示數組中調用 `splice()` 的項的索引或位置。 別忘了,數組的索引是*從 0 開始的*,所以我們要用 `0` 來表示數組中的第一個元素。 `splice()` 的第一個參數代表從數組中的哪個索引開始移除元素,而第二個參數表示要從數組中的這個位置開始刪除多少個元素。 例如:
|
||||
|
||||
```js
|
||||
let array = ['today', 'was', 'not', 'so', 'great'];
|
||||
|
@ -14,18 +14,16 @@ dashedName: comparison-with-the-inequality-operator
|
||||
**例如**
|
||||
|
||||
```js
|
||||
1 != 2
|
||||
1 != "1"
|
||||
1 != '1'
|
||||
1 != true
|
||||
0 != false
|
||||
1 != 2 // true
|
||||
1 != "1" // false
|
||||
1 != '1' // false
|
||||
1 != true // false
|
||||
0 != false // false
|
||||
```
|
||||
|
||||
按順序,這些表達式會返回 `true`、`false`、`false`、`false` 和 `false`。
|
||||
|
||||
# --instructions--
|
||||
|
||||
在 `if` 語句中添加不等運算符 `!=` 以便函數在 `val` 不等於 `99` 時返回字符串 `Not Equal`。
|
||||
在 `if` 語句中添加不等式運算符 `!=` 以便函數在 `val` 不等於 `99` 時返回字符串 `Not Equal`。
|
||||
|
||||
# --hints--
|
||||
|
||||
@ -59,7 +57,7 @@ assert(testNotEqual('12') === 'Not Equal');
|
||||
assert(testNotEqual('bob') === 'Not Equal');
|
||||
```
|
||||
|
||||
你應該使用 `!=` 運算符。
|
||||
你應該使用 `!=` 運算符
|
||||
|
||||
```js
|
||||
assert(code.match(/(?!!==)!=/));
|
||||
|
@ -14,58 +14,56 @@ dashedName: comparison-with-the-less-than-operator
|
||||
**例如:**
|
||||
|
||||
```js
|
||||
2 < 5
|
||||
'3' < 7
|
||||
5 < 5
|
||||
3 < 2
|
||||
'8' < 4
|
||||
2 < 5 // true
|
||||
'3' < 7 // true
|
||||
5 < 5 // false
|
||||
3 < 2 // false
|
||||
'8' < 4 // false
|
||||
```
|
||||
|
||||
按順序,這些表達式會返回 `true`、`true`、`false`、`false` 和 `false`。
|
||||
|
||||
# --instructions--
|
||||
|
||||
添加小於運算符到指定行,使得函數的返回語句有意義。
|
||||
將小於運算符添加到指示的行,以便返回語句有意義。
|
||||
|
||||
# --hints--
|
||||
|
||||
`testLessThan(0)` 應該返回字符串 `Under 25`。
|
||||
`testLessThan(0)` 應該返回字符串 `Under 25`
|
||||
|
||||
```js
|
||||
assert(testLessThan(0) === 'Under 25');
|
||||
```
|
||||
|
||||
`testLessThan(24)` 應該返回字符串 `Under 25`。
|
||||
`testLessThan(24)` 應該返回字符串 `Under 25`
|
||||
|
||||
```js
|
||||
assert(testLessThan(24) === 'Under 25');
|
||||
```
|
||||
|
||||
`testLessThan(25)` 應該返回字符串 `Under 55`。
|
||||
`testLessThan(25)` 應該返回字符串 `Under 55`
|
||||
|
||||
```js
|
||||
assert(testLessThan(25) === 'Under 55');
|
||||
```
|
||||
|
||||
`testLessThan(54)` 應該返回字符串 `Under 55`。
|
||||
`testLessThan(54)` 應該返回字符串 `Under 55`
|
||||
|
||||
```js
|
||||
assert(testLessThan(54) === 'Under 55');
|
||||
```
|
||||
|
||||
`testLessThan(55)` 應該返回字符串 `55 or Over`。
|
||||
`testLessThan(55)` 應該返回字符串 `55 or Over`
|
||||
|
||||
```js
|
||||
assert(testLessThan(55) === '55 or Over');
|
||||
```
|
||||
|
||||
`testLessThan(99)` 應該返回字符串 `55 or Over`。
|
||||
`testLessThan(99)` 應該返回字符串 `55 or Over`
|
||||
|
||||
```js
|
||||
assert(testLessThan(99) === '55 or Over');
|
||||
```
|
||||
|
||||
應該使用 `<` 運算符至少兩次。
|
||||
應該使用 `<` 運算符至少兩次
|
||||
|
||||
```js
|
||||
assert(code.match(/val\s*<\s*('|")*\d+('|")*/g).length > 1);
|
||||
|
@ -14,18 +14,16 @@ dashedName: comparison-with-the-less-than-or-equal-to-operator
|
||||
**例如**
|
||||
|
||||
```js
|
||||
4 <= 5
|
||||
'7' <= 7
|
||||
5 <= 5
|
||||
3 <= 2
|
||||
'8' <= 4
|
||||
4 <= 5 // true
|
||||
'7' <= 7 // true
|
||||
5 <= 5 // true
|
||||
3 <= 2 // false
|
||||
'8' <= 4 // false
|
||||
```
|
||||
|
||||
按順序,這些表達式會返回 `true`、`true`、`true`、`false` 和 `false`。
|
||||
|
||||
# --instructions--
|
||||
|
||||
添加小於等於運算符到指定行,使得函數的返回語句有意義。
|
||||
將小於或等於運算符添加到指示的行,以便返回語句有意義。
|
||||
|
||||
# --hints--
|
||||
|
||||
|
@ -16,17 +16,15 @@ dashedName: comparison-with-the-strict-equality-operator
|
||||
**示例**
|
||||
|
||||
```js
|
||||
3 === 3
|
||||
3 === '3'
|
||||
3 === 3 // true
|
||||
3 === '3' // false
|
||||
```
|
||||
|
||||
這些條件將分別返回 `true` and `false`。
|
||||
|
||||
在第二個例子中,`3` 是一個 `Number` 類型,而 `'3'` 是一個 `String` 類型。
|
||||
|
||||
# --instructions--
|
||||
|
||||
在 `if` 語句中使用嚴格相等運算符,這樣當 `val` 嚴格等於 `7` 時,函數將返回字符串 `Equal`。
|
||||
在 `if` 語句中使用嚴格相等運算符,這樣函數將在 `val` 嚴格等於 `7` 時返回字符串 `Equal`。
|
||||
|
||||
# --hints--
|
||||
|
||||
@ -48,7 +46,7 @@ assert(testStrict(7) === 'Equal');
|
||||
assert(testStrict('7') === 'Not Equal');
|
||||
```
|
||||
|
||||
你應該使用 `===` 運算符。
|
||||
應該使用 `===` 運算符
|
||||
|
||||
```js
|
||||
assert(code.match(/(val\s*===\s*\d+)|(\d+\s*===\s*val)/g).length > 0);
|
||||
|
@ -14,13 +14,11 @@ dashedName: comparison-with-the-strict-inequality-operator
|
||||
**示例**
|
||||
|
||||
```js
|
||||
3 !== 3
|
||||
3 !== '3'
|
||||
4 !== 3
|
||||
3 !== 3 // false
|
||||
3 !== '3' // true
|
||||
4 !== 3 // true
|
||||
```
|
||||
|
||||
按順序,這些表達式會返回 `false`、`true`、`true`。
|
||||
|
||||
# --instructions--
|
||||
|
||||
在 `if` 語句中,添加嚴格不相等運算符,這樣函數在當 `val` 不嚴格等於 `17` 的時候,會返回 `Not Equal`。
|
||||
@ -51,7 +49,7 @@ assert(testStrictNotEqual(12) === 'Not Equal');
|
||||
assert(testStrictNotEqual('bob') === 'Not Equal');
|
||||
```
|
||||
|
||||
應該使用 `!==` 運算符。
|
||||
應該使用 `!==` 運算符
|
||||
|
||||
```js
|
||||
assert(code.match(/(val\s*!==\s*\d+)|(\d+\s*!==\s*val)/g).length > 0);
|
||||
|
@ -25,7 +25,7 @@ dashedName: counting-cards
|
||||
|
||||
# --hints--
|
||||
|
||||
卡牌序列 2、3、4、5、6 應該返回 `5 Bet`
|
||||
卡片序列 2、3、4、5、6 應返回字符串 `5 Bet`
|
||||
|
||||
```js
|
||||
assert(
|
||||
|
@ -21,32 +21,28 @@ FAV_PET = "Dogs";
|
||||
|
||||
你應該始終使用 `const` 關鍵字命名不想重新分配的變量。 這有助於避免給一個常量進行額外的再次賦值。
|
||||
|
||||
命名常量的常見做法是全部使用大寫字母,單詞之間用下劃線分隔。
|
||||
|
||||
**注意:** 對於不可變值,開發人員通常使用大寫變量標識符,對可變值(對象和數組)使用小寫或駝峯式標識符。 你將在後面的挑戰中瞭解有關對象、數組以及不可變和可變值的更多信息。 同樣在後面的挑戰中,你將看到大寫、小寫或駝峯式變量標識符的示例。
|
||||
**注意:** 通常,開發者會用大寫字母作爲常量標識符,用小寫字母或者駝峯命名作爲變量(對象或數組)標識符。 你將在後面的挑戰中瞭解有關對象、數組以及不可變和可變值的更多信息。 同樣在後面的挑戰中,你將看到大寫、小寫或駝峯式變量標識符的示例。
|
||||
|
||||
# --instructions--
|
||||
|
||||
更改代碼,以便使用 `let` 或 `const` 聲明所有變量。 當你希望變量改變時使用 `let`,而當你希望變量保持不變時使用 `const`。 此外,重命名用 `const` 聲明的變量以符合常見做法,這意味着常量應該全部大寫。
|
||||
更改代碼,以便使用 `let` 或 `const` 聲明所有變量。 當你想要改變變量時使用 `let`,當你想要變量保持不變時使用 `const`。 此外,重命名使用 `const` 聲明的變量以符合慣例。
|
||||
|
||||
# --hints--
|
||||
|
||||
`var` 不應存在於你的代碼中。
|
||||
代碼中不應有 `var`。
|
||||
|
||||
```js
|
||||
(getUserInput) => assert(!getUserInput('index').match(/var/g));
|
||||
assert.notMatch(code, /var/g);
|
||||
```
|
||||
|
||||
你應該將 `fCC` 更改爲全部大寫。
|
||||
|
||||
```js
|
||||
(getUserInput) => {
|
||||
assert(getUserInput('index').match(/(FCC)/));
|
||||
assert(!getUserInput('index').match(/fCC/));
|
||||
}
|
||||
assert.match(code, /(FCC)/);
|
||||
assert.notMatch(code, /(fCC)/);
|
||||
```
|
||||
|
||||
`FCC` 應該是一個用 `const` 聲明的常量變量。
|
||||
`FCC` 應該是一個用 `const` 聲明的常量。
|
||||
|
||||
```js
|
||||
assert.equal(FCC, 'freeCodeCamp');
|
||||
@ -56,14 +52,13 @@ assert.match(code, /const\s+FCC/);
|
||||
`fact` 應該用 `let` 聲明。
|
||||
|
||||
```js
|
||||
(getUserInput) => assert(getUserInput('index').match(/(let fact)/g));
|
||||
assert.match(code, /(let\s+fact)/g);
|
||||
```
|
||||
|
||||
`console.log` 應該更改爲打印 `FCC` 和 `fact` 變量。
|
||||
|
||||
```js
|
||||
(getUserInput) =>
|
||||
assert(getUserInput('index').match(/console\.log\(\s*FCC\s*\,\s*fact\s*\)\s*;?/g));
|
||||
assert.match(code, /console\.log\(\s*FCC\s*\,\s*fact\s*\)\s*;?/g);
|
||||
```
|
||||
|
||||
# --seed--
|
||||
|
@ -38,9 +38,13 @@ assert(myVar === 10);
|
||||
應該修改 `myVar = myVar - 1;`。
|
||||
|
||||
```js
|
||||
assert(
|
||||
/let\s*myVar\s*=\s*11;\s*\/*.*\s*([-]{2}\s*myVar|myVar\s*[-]{2});/.test(code)
|
||||
);
|
||||
assert(!code.match(/myVar\s*=\s*myVar\s*[-]\s*1.*?;?/));
|
||||
```
|
||||
|
||||
你不應將 `10` 分配給 `myVar`。
|
||||
|
||||
```js
|
||||
assert(!code.match(/myVar\s*=\s*10.*?;?/));
|
||||
```
|
||||
|
||||
應該對 `myVar` 使用 `--` 運算符。
|
||||
@ -49,7 +53,7 @@ assert(
|
||||
assert(/[-]{2}\s*myVar|myVar\s*[-]{2}/.test(code));
|
||||
```
|
||||
|
||||
不應修改註釋上方的代碼。
|
||||
你不應該修改註釋上面的代碼。
|
||||
|
||||
```js
|
||||
assert(/let myVar = 11;/.test(code));
|
||||
|
@ -23,7 +23,7 @@ myTest();
|
||||
console.log(loc);
|
||||
```
|
||||
|
||||
`myTest()` 函數調用將在控制檯中顯示字符串 `foo`。 `console.log(loc)` 行會產生一個錯誤,因爲 `loc` 沒有定義在函數之外。
|
||||
`myTest()` 函數調用將在控制檯中顯示字符串 `foo`。 `console.log(loc)` 行(在 `myTest` 函數之外)將拋出錯誤,因爲 `loc` 未在函數之外定義。
|
||||
|
||||
# --instructions--
|
||||
|
||||
|
@ -31,13 +31,13 @@ assert(
|
||||
);
|
||||
```
|
||||
|
||||
執行 `updateRecords(recordCollection, 5439, "tracks", "Take a Chance on Me")` 後,`tracks` 的最後一個元素應該爲字符串 `Take a Chance on Me`。
|
||||
在 `updateRecords(recordCollection, 5439, "tracks", "Take a Chance on Me")` 之後,`tracks` 應該有字符串 `Take a Chance on Me` 作爲最後一個也是唯一的元素。
|
||||
|
||||
```js
|
||||
assert(
|
||||
updateRecords(_recordCollection, 5439, 'tracks', 'Take a Chance on Me')[5439][
|
||||
'tracks'
|
||||
].pop() === 'Take a Chance on Me'
|
||||
updateRecords(_recordCollection, 5439, 'tracks', 'Take a Chance on Me') &&
|
||||
_recordCollection[5439]['tracks'].length === 1 &&
|
||||
_recordCollection[5439]['tracks'].pop() === 'Take a Chance on Me'
|
||||
);
|
||||
```
|
||||
|
||||
|
@ -9,7 +9,7 @@ dashedName: understanding-uninitialized-variables
|
||||
|
||||
# --description--
|
||||
|
||||
當 JavaScript 中的變量被聲明的時候,程序內部會給它一個初始值 `undefined`。 當你對一個值爲 `undefined` 的變量進行運算操作的時候,算出來的結果將會是 `NaN`,它的意思是 <dfn>"Not a Number"</dfn>。 當你用一個值是 `undefined` 的變量來做字符串拼接操作的時候,它會轉換成字符串(<dfn>string</dfn>)`undefined`。
|
||||
當 JavaScript 中的變量被聲明的時候,程序內部會給它一個初始值 `undefined`。 當你對一個值爲 `undefined` 的變量進行運算操作的時候,算出來的結果將會是 `NaN`,它的意思是 <dfn>"Not a Number"</dfn>。 如果你用 `undefined` 變量連接一個字符串,你將得到一個 `undefined` 的 <dfn>字符串</dfn>。
|
||||
|
||||
# --instructions--
|
||||
|
||||
|
@ -41,7 +41,7 @@ assert(firstLetterOfLastName === 'L');
|
||||
應該使用方括號表示法。
|
||||
|
||||
```js
|
||||
assert(code.match(/firstLetterOfLastName\s*?=\s*?lastName\[.*?\]/));
|
||||
assert(code.match(/firstLetterOfLastName\s*=\s*lastName\s*\[\s*\d\s*\]/));
|
||||
```
|
||||
|
||||
# --seed--
|
||||
|
@ -39,7 +39,7 @@ assert(thirdLetterOfLastName === 'v');
|
||||
應該使用方括號表示法。
|
||||
|
||||
```js
|
||||
assert(code.match(/thirdLetterOfLastName\s*?=\s*?lastName\[.*?\]/));
|
||||
assert(code.match(/thirdLetterOfLastName\s*=\s*lastName\s*\[\s*\d\s*\]/));
|
||||
```
|
||||
|
||||
# --seed--
|
||||
|
@ -27,6 +27,7 @@ dashedName: refactor-global-variables-out-of-functions
|
||||
`bookList` 應等於 `["The Hound of the Baskervilles", "On The Electrodynamics of Moving Bodies", "Philosophiæ Naturalis Principia Mathematica", "Disquisitiones Arithmeticae"]`.
|
||||
|
||||
```js
|
||||
add(bookList, "Test");
|
||||
assert(
|
||||
JSON.stringify(bookList) ===
|
||||
JSON.stringify([
|
||||
@ -38,11 +39,11 @@ assert(
|
||||
);
|
||||
```
|
||||
|
||||
`newBookList` 應等於 `["The Hound of the Baskervilles", "On The Electrodynamics of Moving Bodies", "Philosophiæ Naturalis Principia Mathematica", "Disquisitiones Arithmeticae", "A Brief History of Time"]`.
|
||||
`add(bookList, "A Brief History of Time")` 應該返回 `["The Hound of the Baskervilles", "On The Electrodynamics of Moving Bodies", "Philosophiæ Naturalis Principia Mathematica", "Disquisitiones Arithmeticae", "A Brief History of Time"]`。
|
||||
|
||||
```js
|
||||
assert(
|
||||
JSON.stringify(newBookList) ===
|
||||
JSON.stringify(add(bookList, "A Brief History of Time")) ===
|
||||
JSON.stringify([
|
||||
'The Hound of the Baskervilles',
|
||||
'On The Electrodynamics of Moving Bodies',
|
||||
@ -53,11 +54,11 @@ assert(
|
||||
);
|
||||
```
|
||||
|
||||
`newerBookList` 應等於 `["The Hound of the Baskervilles", "Philosophiæ Naturalis Principia Mathematica", "Disquisitiones Arithmeticae"]`.
|
||||
`remove(bookList, "On The Electrodynamics of Moving Bodies")` 應該返回 `["The Hound of the Baskervilles", "Philosophiæ Naturalis Principia Mathematica", "Disquisitiones Arithmeticae"]`。
|
||||
|
||||
```js
|
||||
assert(
|
||||
JSON.stringify(newerBookList) ===
|
||||
JSON.stringify(remove(bookList, 'On The Electrodynamics of Moving Bodies')) ===
|
||||
JSON.stringify([
|
||||
'The Hound of the Baskervilles',
|
||||
'Philosophiæ Naturalis Principia Mathematica',
|
||||
@ -66,11 +67,11 @@ assert(
|
||||
);
|
||||
```
|
||||
|
||||
`newestBookList` 應等於 `["The Hound of the Baskervilles", "Philosophiæ Naturalis Principia Mathematica", "Disquisitiones Arithmeticae", "A Brief History of Time"]`.
|
||||
`remove(add(bookList, "A Brief History of Time"), "On The Electrodynamics of Moving Bodies");` 應該返回 `["The Hound of the Baskervilles", "Philosophiæ Naturalis Principia Mathematica", "Disquisitiones Arithmeticae", "A Brief History of Time"]`。
|
||||
|
||||
```js
|
||||
assert(
|
||||
JSON.stringify(newestBookList) ===
|
||||
JSON.stringify(remove(add(bookList, 'A Brief History of Time'), 'On The Electrodynamics of Moving Bodies')) ===
|
||||
JSON.stringify([
|
||||
'The Hound of the Baskervilles',
|
||||
'Philosophiæ Naturalis Principia Mathematica',
|
||||
@ -108,12 +109,6 @@ function remove(bookName) {
|
||||
// Change code above this line
|
||||
}
|
||||
}
|
||||
|
||||
const newBookList = add(bookList, 'A Brief History of Time');
|
||||
const newerBookList = remove(bookList, 'On The Electrodynamics of Moving Bodies');
|
||||
const newestBookList = remove(add(bookList, 'A Brief History of Time'), 'On The Electrodynamics of Moving Bodies');
|
||||
|
||||
console.log(bookList);
|
||||
```
|
||||
|
||||
# --solutions--
|
||||
@ -134,8 +129,4 @@ function remove(bookList, bookName) {
|
||||
}
|
||||
return bookListCopy;
|
||||
}
|
||||
|
||||
const newBookList = add(bookList, 'A Brief History of Time');
|
||||
const newerBookList = remove(bookList, 'On The Electrodynamics of Moving Bodies');
|
||||
const newestBookList = remove(add(bookList, 'A Brief History of Time'), 'On The Electrodynamics of Moving Bodies');
|
||||
```
|
||||
|
@ -60,6 +60,12 @@ assert.isUndefined(addTogether(2, '3'));
|
||||
assert.isUndefined(addTogether(2)([3]));
|
||||
```
|
||||
|
||||
`addTogether("2", 3)` 應該返回 `undefined`。
|
||||
|
||||
```js
|
||||
assert.isUndefined(addTogether('2', 3));
|
||||
```
|
||||
|
||||
# --seed--
|
||||
|
||||
## --seed-contents--
|
||||
|
@ -18,120 +18,123 @@ JavaScript 中,如果一個值在 Boolean 的上下文中的執行結果爲 `t
|
||||
|
||||
# --hints--
|
||||
|
||||
`truthCheck([{"user": "Tinky-Winky", "sex": "male"}, {"user": "Dipsy", "sex": "male"}, {"user": "Laa-Laa", "sex": "female"}, {"user": "Po", "sex": "female"}], "sex")` 應返回 `true`。
|
||||
`truthCheck([{name: "Quincy", role: "Founder", isBot: false}, {name: "Naomi", role: "", isBot: false}, {name: "Camperbot", role: "Bot", isBot: true}], "isBot")` 應該返回 `false`。
|
||||
|
||||
```js
|
||||
assert.strictEqual(
|
||||
truthCheck(
|
||||
[
|
||||
{ user: 'Tinky-Winky', sex: 'male' },
|
||||
{ user: 'Dipsy', sex: 'male' },
|
||||
{ user: 'Laa-Laa', sex: 'female' },
|
||||
{ user: 'Po', sex: 'female' }
|
||||
],
|
||||
'sex'
|
||||
),
|
||||
true
|
||||
);
|
||||
assert.strictEqual(truthCheck(
|
||||
[
|
||||
{ name: "Quincy", role: "Founder", isBot: false },
|
||||
{ name: "Naomi", role: "", isBot: false },
|
||||
{ name: "Camperbot", role: "Bot", isBot: true }
|
||||
],
|
||||
"isBot"), false);
|
||||
```
|
||||
|
||||
`truthCheck([{"user": "Tinky-Winky", "sex": "male"}, {"user": "Dipsy"}, {"user": "Laa-Laa", "sex": "female"}, {"user": "Po", "sex": "female"}], "sex")` 應返回 `false`。
|
||||
`truthCheck([{name: "Quincy", role: "Founder", isBot: false}, {name: "Naomi", role: "", isBot: false}, {name: "Camperbot", role: "Bot", isBot: true}], "name")` 應該返回 `true`。
|
||||
|
||||
```js
|
||||
assert.strictEqual(
|
||||
truthCheck(
|
||||
[
|
||||
{ user: 'Tinky-Winky', sex: 'male' },
|
||||
{ user: 'Dipsy' },
|
||||
{ user: 'Laa-Laa', sex: 'female' },
|
||||
{ user: 'Po', sex: 'female' }
|
||||
],
|
||||
'sex'
|
||||
),
|
||||
false
|
||||
);
|
||||
assert.strictEqual(truthCheck(
|
||||
[
|
||||
{ name: "Quincy", role: "Founder", isBot: false },
|
||||
{ name: "Naomi", role: "", isBot: false },
|
||||
{ name: "Camperbot", role: "Bot", isBot: true }
|
||||
],
|
||||
"name"), true);
|
||||
```
|
||||
|
||||
`truthCheck([{"user": "Tinky-Winky", "sex": "male", "age": 0}, {"user": "Dipsy", "sex": "male", "age": 3}, {"user": "Laa-Laa", "sex": "female", "age": 5}, {"user": "Po", "sex": "female", "age": 4}], "age")` 應返回 `false`。
|
||||
`truthCheck([{name: "Quincy", role: "Founder", isBot: false}, {name: "Naomi", role: "", isBot: false}, {name: "Camperbot", role: "Bot", isBot: true}], "role")` 應該返回 `false`。
|
||||
|
||||
```js
|
||||
assert.strictEqual(
|
||||
truthCheck(
|
||||
[
|
||||
{ user: 'Tinky-Winky', sex: 'male', age: 2 },
|
||||
{ user: 'Dipsy', sex: 'male', age: 0 },
|
||||
{ user: 'Laa-Laa', sex: 'female', age: 5 },
|
||||
{ user: 'Po', sex: 'female', age: 4 }
|
||||
],
|
||||
'age'
|
||||
),
|
||||
false
|
||||
);
|
||||
assert.strictEqual(truthCheck(
|
||||
[
|
||||
{ name: "Quincy", role: "Founder", isBot: false },
|
||||
{ name: "Naomi", role: "", isBot: false },
|
||||
{ name: "Camperbot", role: "Bot", isBot: true }
|
||||
],
|
||||
"role"), false);
|
||||
```
|
||||
|
||||
`truthCheck([{"name": "Pete", "onBoat": true}, {"name": "Repeat", "onBoat": true}, {"name": "FastForward", "onBoat": null}], "onBoat")` 應返回 `false`。
|
||||
`truthCheck([{name: "Pikachu", number: 25, caught: 3}, {name: "Togepi", number: 175, caught: 1}], "number")` 應該返回 `true`。
|
||||
|
||||
```js
|
||||
assert.strictEqual(
|
||||
truthCheck(
|
||||
[
|
||||
{ name: 'Pete', onBoat: true },
|
||||
{ name: 'Repeat', onBoat: true },
|
||||
{ name: 'FastForward', onBoat: null }
|
||||
],
|
||||
'onBoat'
|
||||
),
|
||||
false
|
||||
);
|
||||
assert.strictEqual(truthCheck(
|
||||
[
|
||||
{ name: "Pikachu", number: 25, caught: 3 },
|
||||
{ name: "Togepi", number: 175, caught: 1 },
|
||||
],
|
||||
"number"), true);
|
||||
```
|
||||
|
||||
`truthCheck([{"name": "Pete", "onBoat": true}, {"name": "Repeat", "onBoat": true, "alias": "Repete"}, {"name": "FastForward", "onBoat": true}], "onBoat")` 應返回 `true`。
|
||||
`truthCheck([{name: "Pikachu", number: 25, caught: 3}, {name: "Togepi", number: 175, caught: 1}, {name: "MissingNo", number: NaN, caught: 0}], "caught")` 應該返回 `false`。
|
||||
|
||||
```js
|
||||
assert.strictEqual(
|
||||
truthCheck(
|
||||
[
|
||||
{ name: 'Pete', onBoat: true },
|
||||
{ name: 'Repeat', onBoat: true, alias: 'Repete' },
|
||||
{ name: 'FastForward', onBoat: true }
|
||||
],
|
||||
'onBoat'
|
||||
),
|
||||
true
|
||||
);
|
||||
assert.strictEqual(truthCheck(
|
||||
[
|
||||
{ name: "Pikachu", number: 25, caught: 3 },
|
||||
{ name: "Togepi", number: 175, caught: 1 },
|
||||
{ name: "MissingNo", number: NaN, caught: 0 },
|
||||
],
|
||||
"caught"), false);
|
||||
```
|
||||
|
||||
`truthCheck([{"single": "yes"}], "single")` 應返回 `true`。
|
||||
`truthCheck([{name: "Pikachu", number: 25, caught: 3}, {name: "Togepi", number: 175, caught: 1}, {name: "MissingNo", number: NaN, caught: 0}], "number")` 應該返回 `false`。
|
||||
|
||||
```js
|
||||
assert.strictEqual(truthCheck([{ single: 'yes' }], 'single'), true);
|
||||
assert.strictEqual(truthCheck(
|
||||
[
|
||||
{ name: "Pikachu", number: 25, caught: 3 },
|
||||
{ name: "Togepi", number: 175, caught: 1 },
|
||||
{ name: "MissingNo", number: NaN, caught: 0 },
|
||||
],
|
||||
"number"), false);
|
||||
```
|
||||
|
||||
`truthCheck([{"single": ""}, {"single": "double"}], "single")` 應返回 `false`。
|
||||
`truthCheck([{name: "Quincy", username: "QuincyLarson"}, {name: "Naomi", username: "nhcarrigan"}, {name: "Camperbot"}], "username")` 應該返回 `false`。
|
||||
|
||||
```js
|
||||
assert.strictEqual(
|
||||
truthCheck([{ single: '' }, { single: 'double' }], 'single'),
|
||||
false
|
||||
);
|
||||
assert.strictEqual(truthCheck(
|
||||
[
|
||||
{ name: "Quincy", username: "QuincyLarson" },
|
||||
{ name: "Naomi", username: "nhcarrigan" },
|
||||
{ name: "Camperbot" }
|
||||
],
|
||||
"username"), false);
|
||||
```
|
||||
|
||||
`truthCheck([{"single": "double"}, {"single": undefined}], "single")` 應返回 `false`。
|
||||
`truthCheck([{name: "freeCodeCamp", users: [{name: "Quincy"}, {name: "Naomi"}]}, {name: "Code Radio", users: [{name: "Camperbot"}]}, {name: "", users: []}], "users")` 應該返回 `true`。
|
||||
|
||||
```js
|
||||
assert.strictEqual(
|
||||
truthCheck([{ single: 'double' }, { single: undefined }], 'single'),
|
||||
false
|
||||
);
|
||||
assert.strictEqual(truthCheck(
|
||||
[
|
||||
{ name: "freeCodeCamp", users: [{ name: "Quincy" }, { name: "Naomi" }] },
|
||||
{ name: "Code Radio", users: [{ name: "Camperbot" }] },
|
||||
{ name: "", users: [] },
|
||||
],
|
||||
"users"), true);
|
||||
```
|
||||
|
||||
`truthCheck([{"single": "double"}, {"single": NaN}], "single")` 應返回 `false`。
|
||||
`truthCheck([{id: 1, data: {url: "https://freecodecamp.org", name: "freeCodeCamp"}}, {id: 2, data: {url: "https://coderadio.freecodecamp.org/", name: "CodeRadio"}}, {id: null, data: {}}], "data")` 應該返回 `true`。
|
||||
|
||||
```js
|
||||
assert.strictEqual(
|
||||
truthCheck([{ single: 'double' }, { single: NaN }], 'single'),
|
||||
false
|
||||
);
|
||||
assert.strictEqual(truthCheck(
|
||||
[
|
||||
{ id: 1, data: { url: "https://www.freecodecamp.org", name: "freeCodeCamp" } },
|
||||
{ id: 2, data: { url: "https://coderadio.freecodecamp.org/", name: "CodeRadio" } },
|
||||
{ id: null, data: {} },
|
||||
],
|
||||
"data"), true);
|
||||
```
|
||||
|
||||
`truthCheck([{id: 1, data: {url: "https://freecodecamp.org", name: "freeCodeCamp"}}, {id: 2, data: {url: "https://coderadio.freecodecamp.org/", name: "CodeRadio"}}, {id: null, data: {}}], "id")` 應該返回 `false`。
|
||||
|
||||
```js
|
||||
assert.strictEqual(truthCheck(
|
||||
[
|
||||
{ id: 1, data: { url: "https://www.freecodecamp.org", name: "freeCodeCamp" } },
|
||||
{ id: 2, data: { url: "https://coderadio.freecodecamp.org/", name: "CodeRadio" } },
|
||||
{ id: null, data: {} },
|
||||
],
|
||||
"id"), false);
|
||||
```
|
||||
|
||||
# --seed--
|
||||
@ -143,7 +146,7 @@ function truthCheck(collection, pre) {
|
||||
return pre;
|
||||
}
|
||||
|
||||
truthCheck([{"user": "Tinky-Winky", "sex": "male"}, {"user": "Dipsy", "sex": "male"}, {"user": "Laa-Laa", "sex": "female"}, {"user": "Po", "sex": "female"}], "sex");
|
||||
truthCheck([{name: "Quincy", role: "Founder", isBot: false}, {name: "Naomi", role: "", isBot: false}, {name: "Camperbot", role: "Bot", isBot: true}], "isBot");
|
||||
```
|
||||
|
||||
# --solutions--
|
||||
|
@ -45,6 +45,18 @@ assert.deepEqual(uniteUnique([1, 2, 3], [5, 2, 1, 4], [2, 1], [6, 7, 8]), [
|
||||
]);
|
||||
```
|
||||
|
||||
`uniteUnique([1, 3, 2], [5, 4], [5, 6])` 應該返回 `[1, 3, 2, 5, 4, 6]`。
|
||||
|
||||
```js
|
||||
assert.deepEqual(uniteUnique([1, 3, 2], [5, 4], [5, 6]), [1, 3, 2, 5, 4, 6]);
|
||||
```
|
||||
|
||||
`uniteUnique([1, 3, 2, 3], [5, 2, 1, 4], [2, 1])` 應該返回 `[1, 3, 2, 5, 4]`。
|
||||
|
||||
```js
|
||||
assert.deepEqual(uniteUnique([1, 3, 2, 3], [5, 2, 1, 4], [2, 1]), [1, 3, 2, 5, 4]);
|
||||
```
|
||||
|
||||
# --seed--
|
||||
|
||||
## --seed-contents--
|
||||
@ -62,7 +74,11 @@ uniteUnique([1, 3, 2], [5, 2, 1, 4], [2, 1]);
|
||||
```js
|
||||
function uniteUnique(arr) {
|
||||
return [].slice.call(arguments).reduce(function(a, b) {
|
||||
return [].concat(a, b.filter(function(e) {return a.indexOf(e) === -1;}));
|
||||
return [].concat(
|
||||
a,
|
||||
b.filter(function(e, currentIndex) {
|
||||
return b.indexOf(e) === currentIndex && a.indexOf(e) === -1;
|
||||
}));
|
||||
}, []);
|
||||
}
|
||||
```
|
||||
|
Reference in New Issue
Block a user