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