919 B

id, title, challengeType, forumTopicId
id title challengeType forumTopicId
a6e40f1041b06c996f7b2406 按参数过滤数组 5 16016

--description--

请写一个函数来检查数组(第一个参数 arr)中的元素,并返回数组中第一个通过校验测试的元素。其中,“通过校验测试”指的是对于数组中的一个元素 x,若 func(x) 返回的结果为 true,则校验测试通过。如果没有元素通过测试,请返回 undefined

--hints--

findElement([1, 3, 5, 8, 9, 10], function(num) { return num % 2 === 0; }) 应返回 8。

assert.strictEqual(
  findElement([1, 3, 5, 8, 9, 10], function (num) {
    return num % 2 === 0;
  }),
  8
);

findElement([1, 3, 5, 9], function(num) { return num % 2 === 0; }) 应返回 undefined。

assert.strictEqual(
  findElement([1, 3, 5, 9], function (num) {
    return num % 2 === 0;
  }),
  undefined
);

--solutions--