--- id: 587d7dab367417b2b2512b6e title: Use the every Method to Check that Every Element in an Array Meets a Criteria challengeType: 1 videoUrl: '' localeTitle: 使用every方法检查数组中的每个元素是否符合条件 --- ## Description
every方法都使用数组来检查每个元素是否通过了特定的测试。它返回一个布尔值 - 如果所有值都满足条件,则返回true否则返回false 。例如,以下代码将检查numbers数组中的每个元素是否小于10:
var numbers = [1,5,8,0,10,11];
numbers.every(function(currentValue){
return currentValue <10;
});
//返回false
## Instructions
使用checkPositive函数中的every方法检查arr每个元素是否为正数。该函数应返回一个布尔值。
## Tests
```yml tests: - text: 您的代码应该使用every方法。 testString: 'assert(code.match(/\.every/g), "Your code should use the every method.");' - text: 'checkPositive([1, 2, 3, -4, 5])应该返回false 。' testString: 'assert(!checkPositive([1, 2, 3, -4, 5]), "checkPositive([1, 2, 3, -4, 5]) should return false.");' - text: 'checkPositive([1, 2, 3, 4, 5])应该返回true 。' testString: 'assert(checkPositive([1, 2, 3, 4, 5]), "checkPositive([1, 2, 3, 4, 5]) should return true.");' - text: 'checkPositive([1, -2, 3, -4, 5])应该返回false 。' testString: 'assert(!checkPositive([1, -2, 3, -4, 5]), "checkPositive([1, -2, 3, -4, 5]) should return false.");' ```
## Challenge Seed
```js function checkPositive(arr) { // Add your code below this line // Add your code above this line } checkPositive([1, 2, 3, -4, 5]); ```
## Solution
```js // solution required ```