2018-09-30 23:01:58 +01:00
---
id: 587d7dab367417b2b2512b6f
title: Use the some Method to Check that Any Elements in an Array Meet a Criteria
challengeType: 1
2019-08-05 09:17:33 -07:00
forumTopicId: 301314
2021-01-13 03:31:00 +01:00
dashedName: use-the-some-method-to-check-that-any-elements-in-an-array-meet-a-criteria
2018-09-30 23:01:58 +01:00
---
2020-11-27 19:02:05 +01:00
# --description--
The `some` method works with arrays to check if *any* element passes a particular test. It returns a Boolean value - `true` if any of the values meet the criteria, `false` if not.
For example, the following code would check if any element in the `numbers` array is less than 10:
2019-05-17 06:20:30 -07:00
```js
var numbers = [10, 50, 8, 220, 110, 11];
numbers.some(function(currentValue) {
return currentValue < 10 ;
});
// Returns true
```
2020-11-27 19:02:05 +01:00
# --instructions--
Use the `some` method inside the `checkPositive` function to check if any element in `arr` is positive. The function should return a Boolean value.
2018-09-30 23:01:58 +01:00
2020-11-27 19:02:05 +01:00
# --hints--
2018-09-30 23:01:58 +01:00
2020-11-27 19:02:05 +01:00
Your code should use the `some` method.
```js
assert(code.match(/\.some/g));
```
2018-09-30 23:01:58 +01:00
2020-11-27 19:02:05 +01:00
`checkPositive([1, 2, 3, -4, 5])` should return `true` .
2018-09-30 23:01:58 +01:00
2020-11-27 19:02:05 +01:00
```js
assert(checkPositive([1, 2, 3, -4, 5]));
2018-09-30 23:01:58 +01:00
```
2020-11-27 19:02:05 +01:00
`checkPositive([1, 2, 3, 4, 5])` should return `true` .
2018-09-30 23:01:58 +01:00
2020-11-27 19:02:05 +01:00
```js
assert(checkPositive([1, 2, 3, 4, 5]));
```
2018-09-30 23:01:58 +01:00
2020-11-27 19:02:05 +01:00
`checkPositive([-1, -2, -3, -4, -5])` should return `false` .
```js
assert(!checkPositive([-1, -2, -3, -4, -5]));
```
# --seed--
## --seed-contents--
2018-09-30 23:01:58 +01:00
```js
function checkPositive(arr) {
2020-03-08 07:46:28 -07:00
// Only change code below this line
2018-10-08 01:01:53 +01:00
2020-03-08 07:46:28 -07:00
// Only change code above this line
2018-09-30 23:01:58 +01:00
}
checkPositive([1, 2, 3, -4, 5]);
```
2020-11-27 19:02:05 +01:00
# --solutions--
2018-09-30 23:01:58 +01:00
```js
2019-04-28 02:01:14 -07:00
function checkPositive(arr) {
2020-03-08 07:46:28 -07:00
// Only change code below this line
2019-04-28 02:01:14 -07:00
return arr.some(elem => elem > 0);
2020-03-08 07:46:28 -07:00
// Only change code above this line
2019-04-28 02:01:14 -07:00
}
checkPositive([1, 2, 3, -4, 5]);
2018-09-30 23:01:58 +01:00
```