freeCodeCamp/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/functional-programming/use-the-every-method-to-check-that-every-element-in-an-array-meets-a-criteria.chinese.md
Kristofer Koishigawa b3213fc892 fix(i18n): chinese test suite (#38220)
* fix: Chinese test suite

Add localeTiltes, descriptions, and adjust test text and testStrings to get the automated test suite working.

* fix: ran script, updated testStrings and solutions
2020-03-03 18:49:47 +05:30

1.9 KiB
Raw Blame History

id, title, challengeType, videoUrl, localeTitle
id title challengeType videoUrl localeTitle
587d7dab367417b2b2512b6e Use the every Method to Check that Every Element in an Array Meets a Criteria 1 使用every方法检查数组中的每个元素是否符合条件

Description

every方法都使用数组来检查每个元素是否通过了特定的测试。它返回一个布尔值 - 如果所有值都满足条件,则返回true否则返回false 。例如,以下代码将检查numbers数组中的每个元素是否小于10
var numbers = [1,5,8,0,10,11];
numbers.everyfunctioncurrentValue{
return currentValue <10;
};
//返回false

Instructions

使用checkPositive函数中的every方法检查arr每个元素是否为正数。该函数应返回一个布尔值。

Tests

tests:
  - text: 您的代码应该使用<code>every</code>方法。
    testString: assert(code.match(/\.every/g));
  - text: '<code>checkPositive([1, 2, 3, -4, 5])</code>应该返回<code>false</code> 。'
    testString: assert.isFalse(checkPositive([1, 2, 3, -4, 5]));
  - text: '<code>checkPositive([1, 2, 3, 4, 5])</code>应该返回<code>true</code> 。'
    testString: assert.isTrue(checkPositive([1, 2, 3, 4, 5]));
  - text: '<code>checkPositive([1, -2, 3, -4, 5])</code>应该返回<code>false</code> 。'
    testString: assert.isFalse(checkPositive([1, -2, 3, -4, 5]));

Challenge Seed

function checkPositive(arr) {
  // Add your code below this line


  // Add your code above this line
}
checkPositive([1, 2, 3, -4, 5]);

Solution

// solution required