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
2018-09-30 23:01:58 +01:00
---
## Description
<section id='description'>
The <code>some</code> method works with arrays to check if <em>any</em> element passes a particular test. It returns a Boolean value - <code>true</code> if any of the values meet the criteria, <code>false</code> if not.
For example, the following code would check if any element in the <code>numbers</code> 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
```
2018-09-30 23:01:58 +01:00
</section>
## Instructions
<section id='instructions'>
Use the <code>some</code> method inside the <code>checkPositive</code> function to check if any element in <code>arr</code> is positive. The function should return a Boolean value.
</section>
## Tests
<section id='tests'>
```yml
2018-10-04 14:37:37 +01:00
tests:
- text: Your code should use the <code>some</code> method.
2019-07-24 01:47:32 -07:00
testString: assert(code.match(/\.some/g));
2018-10-20 21:02:47 +03:00
- text: <code>checkPositive([1, 2, 3, -4, 5])</code> should return <code>true</code>.
2019-07-24 01:47:32 -07:00
testString: assert(checkPositive([1, 2, 3, -4, 5]));
2018-10-20 21:02:47 +03:00
- text: <code>checkPositive([1, 2, 3, 4, 5])</code> should return <code>true</code>.
2019-07-24 01:47:32 -07:00
testString: assert(checkPositive([1, 2, 3, 4, 5]));
2018-10-20 21:02:47 +03:00
- text: <code>checkPositive([-1, -2, -3, -4, -5])</code> should return <code>false</code>.
2019-07-24 01:47:32 -07:00
testString: assert(!checkPositive([-1, -2, -3, -4, -5]));
2018-09-30 23:01:58 +01:00
```
</section>
## Challenge Seed
<section id='challengeSeed'>
<div id='js-seed'>
```js
function checkPositive(arr) {
// Add your code below this line
2018-10-08 01:01:53 +01:00
2018-09-30 23:01:58 +01:00
// Add your code above this line
}
checkPositive([1, 2, 3, -4, 5]);
```
</div>
</section>
## Solution
<section id='solution'>
```js
2019-04-28 02:01:14 -07:00
function checkPositive(arr) {
// Add your code below this line
return arr.some(elem => elem > 0);
// Add your code above this line
}
checkPositive([1, 2, 3, -4, 5]);
2018-09-30 23:01:58 +01:00
```
2019-07-18 08:24:12 -07:00
2018-09-30 23:01:58 +01:00
</section>