Oliver Eyton-Williams ee1e8abd87
feat(curriculum): restore seed + solution to Chinese (#40683)
* 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>
2021-01-12 19:31:00 -07:00

1.2 KiB

id, title, challengeType, forumTopicId, dashedName
id title challengeType forumTopicId dashedName
a6e40f1041b06c996f7b2406 按参数过滤数组 5 16016 finders-keepers

--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
);

--seed--

--seed-contents--

function findElement(arr, func) {
  let num = 0;
  return num;
}

findElement([1, 2, 3, 4], num => num % 2 === 0);

--solutions--

function findElement(arr, func) {
  return arr.filter(func)[0];
}

findElement([1, 2, 3, 4], num => num % 2 === 0);