every方法都使用数组来检查每个元素是否通过了特定的测试。它返回一个布尔值 - 如果所有值都满足条件,则返回true否则返回false 。例如,以下代码将检查numbers数组中的每个元素是否小于10: var numbers = [1,5,8,0,10,11];
numbers.every(function(currentValue){
return currentValue <10;
});
//返回false
checkPositive函数中的every方法检查arr每个元素是否为正数。该函数应返回一个布尔值。 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.");'
```