some方法用于检测数组中任何元素是否满足指定条件。如果有一个元素满足条件,返回布尔值true,反之返回false。
举个例子,下面的代码检测数组numbers中是否有元素小于10:
```js
var numbers = [10, 50, 8, 220, 110, 11];
numbers.some(function(currentValue) {
return currentValue < 10;
});
// Returns true
```
checkPositive函数值中使用some检查arr中是否有元素为正数,函数应返回一个布尔值。
somemethod.
testString: assert(code.match(/\.some/g));
- text: checkPositive([1, 2, 3, -4, 5])应返回true。
testString: assert(checkPositive([1, 2, 3, -4, 5]));
- text: checkPositive([1, 2, 3, 4, 5])应返回true。
testString: assert(checkPositive([1, 2, 3, 4, 5]));
- text: checkPositive([-1, -2, -3, -4, -5])应返回false。
testString: assert(!checkPositive([-1, -2, -3, -4, -5]));
```