Files
.github
api-server
client
config
curriculum
challenges
_meta
arabic
chinese
english
01-responsive-web-design
02-javascript-algorithms-and-data-structures
basic-algorithm-scripting
basic-data-structures
basic-javascript
debugging
es6
functional-programming
add-elements-to-the-end-of-an-array-using-concat-instead-of-push.english.md
apply-functional-programming-to-convert-strings-to-url-slugs.english.md
avoid-mutations-and-side-effects-using-functional-programming.english.md
combine-an-array-into-a-string-using-the-join-method.english.md
combine-two-arrays-using-the-concat-method.english.md
implement-map-on-a-prototype.english.md
implement-the-filter-method-on-a-prototype.english.md
introduction-to-currying-and-partial-application.english.md
learn-about-functional-programming.english.md
pass-arguments-to-avoid-external-dependence-in-a-function.english.md
refactor-global-variables-out-of-functions.english.md
remove-elements-from-an-array-using-slice-instead-of-splice.english.md
return-a-sorted-array-without-changing-the-original-array.english.md
return-part-of-an-array-using-the-slice-method.english.md
sort-an-array-alphabetically-using-the-sort-method.english.md
split-a-string-into-an-array-using-the-split-method.english.md
understand-functional-programming-terminology.english.md
understand-the-hazards-of-using-imperative-code.english.md
use-the-every-method-to-check-that-every-element-in-an-array-meets-a-criteria.english.md
use-the-filter-method-to-extract-data-from-an-array.english.md
use-the-map-method-to-extract-data-from-an-array.english.md
use-the-reduce-method-to-analyze-data.english.md
use-the-some-method-to-check-that-any-elements-in-an-array-meet-a-criteria.english.md
intermediate-algorithm-scripting
javascript-algorithms-and-data-structures-projects
object-oriented-programming
regular-expressions
03-front-end-libraries
04-data-visualization
05-apis-and-microservices
06-information-security-and-quality-assurance
08-coding-interview-prep
09-certificates
portuguese
russian
spanish
formattingConversion
math-challenges
requiresTests
schema
test
.babelrc
.editorconfig
.npmignore
.travis.yml
CHANGELOG.md
LICENSE.md
commitizen.config.js
commitlint.config.js
create-challenge-bundle.js
getChallenges.js
gulpfile.js
index.js
lib.js
md-translation.js
package-entry.js
package-lock.json
package.json
utils.js
docs
guide
mock-guide
tools
.editorconfig
.eslintignore
.eslintrc.json
.gitattributes
.gitignore
.node-inspectorrc
.prettierrc
.snyk
.travis.yml
.vcmrc
CODE_OF_CONDUCT.md
CONTRIBUTING.md
Dockerfile.tests
LICENSE.md
README.french.md
README.italian.md
README.md
change_volumes_owner.sh
docker-compose-shared.yml
docker-compose.tests.yml
docker-compose.yml
lerna.json
netlify.toml
package-lock.json
package.json
sample.env
freeCodeCamp/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/functional-programming/use-the-every-method-to-check-that-every-element-in-an-array-meets-a-criteria.english.md

65 lines
2.1 KiB
Markdown
Raw Normal View History

---
id: 587d7dab367417b2b2512b6e
title: Use the every Method to Check that Every Element in an Array Meets a Criteria
challengeType: 1
---
## Description
<section id='description'>
The <code>every</code> method works with arrays to check if <em>every</em> element passes a particular test. It returns a Boolean value - <code>true</code> if all values meet the criteria, <code>false</code> if not.
For example, the following code would check if every element in the <code>numbers</code> array is less than 10:
<blockquote>var numbers = [1, 5, 8, 0, 10, 11];<br>numbers.every(function(currentValue) {<br>&nbsp;&nbsp;return currentValue < 10;<br>});<br>// Returns false</blockquote>
</section>
## Instructions
<section id='instructions'>
Use the <code>every</code> method inside the <code>checkPositive</code> function to check if every element in <code>arr</code> is positive. The function should return a Boolean value.
</section>
## Tests
<section id='tests'>
```yml
tests:
- text: Your code should use the <code>every</code> method.
testString: assert(code.match(/\.every/g), 'Your code should use the <code>every</code> method.');
- text: <code>checkPositive([1, 2, 3, -4, 5])</code> should return <code>false</code>.
testString: assert(!checkPositive([1, 2, 3, -4, 5]), '<code>checkPositive([1, 2, 3, -4, 5])</code> should return <code>false</code>.');
- text: <code>checkPositive([1, 2, 3, 4, 5])</code> should return <code>true</code>.
testString: assert(checkPositive([1, 2, 3, 4, 5]), '<code>checkPositive([1, 2, 3, 4, 5])</code> should return <code>true</code>.');
- text: <code>checkPositive([1, -2, 3, -4, 5])</code> should return <code>false</code>.
testString: assert(!checkPositive([1, -2, 3, -4, 5]), '<code>checkPositive([1, -2, 3, -4, 5])</code> should return <code>false</code>.');
```
</section>
## Challenge Seed
<section id='challengeSeed'>
<div id='js-seed'>
```js
function checkPositive(arr) {
// Add your code below this line
// Add your code above this line
}
checkPositive([1, 2, 3, -4, 5]);
```
</div>
</section>
## Solution
<section id='solution'>
```js
// solution required
```
</section>