* 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>
1.5 KiB
1.5 KiB
id, title, challengeType, forumTopicId, dashedName
id | title | challengeType | forumTopicId | dashedName |
---|---|---|---|---|
587d7dab367417b2b2512b6f | 使用 some 方法检查数组中是否有元素是否符合条件 | 1 | 301314 | use-the-some-method-to-check-that-any-elements-in-an-array-meet-a-criteria |
--description--
some
方法用于检测数组中任何元素是否满足指定条件。如果有一个元素满足条件,返回布尔值true
,反之返回false
。
举个例子,下面的代码检测数组numbers
中是否有元素小于10:
var numbers = [10, 50, 8, 220, 110, 11];
numbers.some(function(currentValue) {
return currentValue < 10;
});
// Returns true
--instructions--
在checkPositive
函数值中使用some
检查arr
中是否有元素为正数,函数应返回一个布尔值。
--hints--
应该使用some
method.
assert(code.match(/\.some/g));
checkPositive([1, 2, 3, -4, 5])
应返回true
。
assert(checkPositive([1, 2, 3, -4, 5]));
checkPositive([1, 2, 3, 4, 5])
应返回true
。
assert(checkPositive([1, 2, 3, 4, 5]));
checkPositive([-1, -2, -3, -4, -5])
应返回false
。
assert(!checkPositive([-1, -2, -3, -4, -5]));
--seed--
--seed-contents--
function checkPositive(arr) {
// Only change code below this line
// Only change code above this line
}
checkPositive([1, 2, 3, -4, 5]);
--solutions--
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]);