2018-10-10 18:03:03 -04:00
|
|
|
|
---
|
|
|
|
|
id: a10d2431ad0c6a099a4b8b52
|
|
|
|
|
title: Everything Be True
|
|
|
|
|
isRequired: true
|
|
|
|
|
challengeType: 5
|
|
|
|
|
videoUrl: ''
|
|
|
|
|
localeTitle: 一切都是真的
|
|
|
|
|
---
|
|
|
|
|
|
|
|
|
|
## Description
|
2019-11-19 19:54:48 -05:00
|
|
|
|
<section id="description">检查谓词(第二个参数)是否对集合的所有元素(第一个参数)都是<dfn>真实的</dfn> 。换句话说,您将获得一个对象的数组集合。谓语<code>pre</code>将一个对象的属性,你需要返回<code>true</code> ,如果它的值是<code>truthy</code> 。否则,返回<code>false</code> 。在JavaScript中, <code>truthy</code>值是在布尔上下文中计算时转换为<code>true</code>的值。请记住,您可以通过点表示法或<code>[]</code>表示法访问对象属性。如果卡住,请记得使用<a href="https://www.freecodecamp.org/forum/t/how-to-get-help-when-you-are-stuck-coding/19514" target="_blank">Read-Search-Ask</a> 。尝试配对程序。编写自己的代码。 </section>
|
2018-10-10 18:03:03 -04:00
|
|
|
|
|
|
|
|
|
## Instructions
|
|
|
|
|
<section id="instructions">
|
|
|
|
|
</section>
|
|
|
|
|
|
|
|
|
|
## Tests
|
|
|
|
|
<section id='tests'>
|
|
|
|
|
|
|
|
|
|
```yml
|
|
|
|
|
tests:
|
|
|
|
|
- text: '<code>truthCheck([{"user": "Tinky-Winky", "sex": "male"}, {"user": "Dipsy", "sex": "male"}, {"user": "Laa-Laa", "sex": "female"}, {"user": "Po", "sex": "female"}], "sex")</code>应该返回true。'
|
|
|
|
|
testString: 'assert.strictEqual(truthCheck([{"user": "Tinky-Winky", "sex": "male"}, {"user": "Dipsy", "sex": "male"}, {"user": "Laa-Laa", "sex": "female"}, {"user": "Po", "sex": "female"}], "sex"), true, "<code>truthCheck([{"user": "Tinky-Winky", "sex": "male"}, {"user": "Dipsy", "sex": "male"}, {"user": "Laa-Laa", "sex": "female"}, {"user": "Po", "sex": "female"}], "sex")</code> should return true.");'
|
|
|
|
|
- text: '<code>truthCheck([{"user": "Tinky-Winky", "sex": "male"}, {"user": "Dipsy"}, {"user": "Laa-Laa", "sex": "female"}, {"user": "Po", "sex": "female"}], "sex")</code>应该返回false。'
|
|
|
|
|
testString: 'assert.strictEqual(truthCheck([{"user": "Tinky-Winky", "sex": "male"}, {"user": "Dipsy"}, {"user": "Laa-Laa", "sex": "female"}, {"user": "Po", "sex": "female"}], "sex"), false, "<code>truthCheck([{"user": "Tinky-Winky", "sex": "male"}, {"user": "Dipsy"}, {"user": "Laa-Laa", "sex": "female"}, {"user": "Po", "sex": "female"}], "sex")</code> should return false.");'
|
|
|
|
|
- text: '<code>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")</code>应该返回false。'
|
|
|
|
|
testString: '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, "<code>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")</code> should return false.");'
|
|
|
|
|
- text: '<code>truthCheck([{"name": "Pete", "onBoat": true}, {"name": "Repeat", "onBoat": true}, {"name": "FastFoward", "onBoat": null}], "onBoat")</code>应该返回false'
|
|
|
|
|
testString: 'assert.strictEqual(truthCheck([{"name": "Pete", "onBoat": true}, {"name": "Repeat", "onBoat": true}, {"name": "FastFoward", "onBoat": null}], "onBoat"), false, "<code>truthCheck([{"name": "Pete", "onBoat": true}, {"name": "Repeat", "onBoat": true}, {"name": "FastFoward", "onBoat": null}], "onBoat")</code> should return false");'
|
|
|
|
|
- text: '<code>truthCheck([{"name": "Pete", "onBoat": true}, {"name": "Repeat", "onBoat": true, "alias": "Repete"}, {"name": "FastFoward", "onBoat": true}], "onBoat")</code>应该返回true'
|
|
|
|
|
testString: 'assert.strictEqual(truthCheck([{"name": "Pete", "onBoat": true}, {"name": "Repeat", "onBoat": true, "alias": "Repete"}, {"name": "FastFoward", "onBoat": true}], "onBoat"), true, "<code>truthCheck([{"name": "Pete", "onBoat": true}, {"name": "Repeat", "onBoat": true, "alias": "Repete"}, {"name": "FastFoward", "onBoat": true}], "onBoat")</code> should return true");'
|
|
|
|
|
- text: '<code>truthCheck([{"single": "yes"}], "single")</code>应该返回true'
|
|
|
|
|
testString: 'assert.strictEqual(truthCheck([{"single": "yes"}], "single"), true, "<code>truthCheck([{"single": "yes"}], "single")</code> should return true");'
|
|
|
|
|
- text: '<code>truthCheck([{"single": ""}, {"single": "double"}], "single")</code>应该返回false'
|
|
|
|
|
testString: 'assert.strictEqual(truthCheck([{"single": ""}, {"single": "double"}], "single"), false, "<code>truthCheck([{"single": ""}, {"single": "double"}], "single")</code> should return false");'
|
|
|
|
|
- text: '<code>truthCheck([{"single": "double"}, {"single": undefined}], "single")</code>应返回false'
|
|
|
|
|
testString: 'assert.strictEqual(truthCheck([{"single": "double"}, {"single": undefined}], "single"), false, "<code>truthCheck([{"single": "double"}, {"single": undefined}], "single")</code> should return false");'
|
|
|
|
|
- text: '<code>truthCheck([{"single": "double"}, {"single": NaN}], "single")</code>应返回false'
|
|
|
|
|
testString: 'assert.strictEqual(truthCheck([{"single": "double"}, {"single": NaN}], "single"), false, "<code>truthCheck([{"single": "double"}, {"single": NaN}], "single")</code> should return false");'
|
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
</section>
|
|
|
|
|
|
|
|
|
|
## Challenge Seed
|
|
|
|
|
<section id='challengeSeed'>
|
|
|
|
|
|
|
|
|
|
<div id='js-seed'>
|
|
|
|
|
|
|
|
|
|
```js
|
|
|
|
|
function truthCheck(collection, pre) {
|
|
|
|
|
// Is everyone being true?
|
|
|
|
|
return pre;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
truthCheck([{"user": "Tinky-Winky", "sex": "male"}, {"user": "Dipsy", "sex": "male"}, {"user": "Laa-Laa", "sex": "female"}, {"user": "Po", "sex": "female"}], "sex");
|
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
</section>
|
|
|
|
|
|
|
|
|
|
## Solution
|
|
|
|
|
<section id='solution'>
|
|
|
|
|
|
|
|
|
|
```js
|
|
|
|
|
// solution required
|
|
|
|
|
```
|
|
|
|
|
</section>
|