* 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
1.9 KiB
1.9 KiB
id, title, challengeType, videoUrl, localeTitle
id | title | challengeType | videoUrl | localeTitle |
---|---|---|---|---|
587d7dab367417b2b2512b6f | Use the some Method to Check that Any Elements in an Array Meet a Criteria | 1 | 使用某些方法检查阵列中的任何元素是否符合条件 |
Description
some
方法适用于数组,以检查是否有任何元素通过了特定的测试。它返回一个布尔值 - 如果任何值满足条件,则返回true
否则返回false
。例如,以下代码将检查numbers
数组中的任何元素是否小于10: var number = [10,50,8,220,110,11];
numbers.some(function(currentValue){
return currentValue <10;
});
//返回true
Instructions
checkPositive
函数中的some
方法检查arr
任何元素是否为正数。该函数应返回一个布尔值。 Tests
tests:
- text: 您的代码应该使用<code>some</code>方法。
testString: assert(code.match(/\.some/g));
- text: '<code>checkPositive([1, 2, 3, -4, 5])</code>应该返回<code>true</code> 。'
testString: assert(checkPositive([1, 2, 3, -4, 5]));
- text: '<code>checkPositive([1, 2, 3, 4, 5])</code>应该返回<code>true</code> 。'
testString: assert(checkPositive([1, 2, 3, 4, 5]));
- text: '<code>checkPositive([-1, -2, -3, -4, -5])</code>应该返回<code>false</code> 。'
testString: assert(!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