* feat(tools): add seed/solution restore script * chore(curriculum): remove empty sections' markers * chore(curriculum): add seed + solution to Chinese * chore: remove old formatter * fix: update getChallenges parse translated challenges separately, without reference to the source * chore(curriculum): add dashedName to English * chore(curriculum): add dashedName to Chinese * refactor: remove unused challenge property 'name' * fix: relax dashedName requirement * fix: stray tag Remove stray `pre` tag from challenge file. Signed-off-by: nhcarrigan <nhcarrigan@gmail.com> Co-authored-by: nhcarrigan <nhcarrigan@gmail.com>
77 lines
1.6 KiB
Markdown
77 lines
1.6 KiB
Markdown
---
|
|
id: 587d7dab367417b2b2512b6f
|
|
title: Use the some Method to Check that Any Elements in an Array Meet a Criteria
|
|
challengeType: 1
|
|
forumTopicId: 301314
|
|
dashedName: use-the-some-method-to-check-that-any-elements-in-an-array-meet-a-criteria
|
|
---
|
|
|
|
# --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:
|
|
|
|
```js
|
|
var numbers = [10, 50, 8, 220, 110, 11];
|
|
numbers.some(function(currentValue) {
|
|
return currentValue < 10;
|
|
});
|
|
// Returns true
|
|
```
|
|
|
|
# --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.
|
|
|
|
# --hints--
|
|
|
|
Your code should use the `some` method.
|
|
|
|
```js
|
|
assert(code.match(/\.some/g));
|
|
```
|
|
|
|
`checkPositive([1, 2, 3, -4, 5])` should return `true`.
|
|
|
|
```js
|
|
assert(checkPositive([1, 2, 3, -4, 5]));
|
|
```
|
|
|
|
`checkPositive([1, 2, 3, 4, 5])` should return `true`.
|
|
|
|
```js
|
|
assert(checkPositive([1, 2, 3, 4, 5]));
|
|
```
|
|
|
|
`checkPositive([-1, -2, -3, -4, -5])` should return `false`.
|
|
|
|
```js
|
|
assert(!checkPositive([-1, -2, -3, -4, -5]));
|
|
```
|
|
|
|
# --seed--
|
|
|
|
## --seed-contents--
|
|
|
|
```js
|
|
function checkPositive(arr) {
|
|
// Only change code below this line
|
|
|
|
|
|
// Only change code above this line
|
|
}
|
|
checkPositive([1, 2, 3, -4, 5]);
|
|
```
|
|
|
|
# --solutions--
|
|
|
|
```js
|
|
function checkPositive(arr) {
|
|
// Only change code below this line
|
|
return arr.some(elem => elem > 0);
|
|
// Only change code above this line
|
|
}
|
|
checkPositive([1, 2, 3, -4, 5]);
|
|
```
|