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

2.1 KiB

id, title, challengeType, forumTopicId, dashedName
id title challengeType forumTopicId dashedName
a5deed1811a43193f9f1c841 根据参数删除数组元素 5 16010 drop-it

--description--

给定数组 arr,从数组的第一个元素开始,用函数 func 来检查数组的每个元素是否返回 true。如果返回 false,就把这个元素删除。持续执行删除操作,直到某个元素传入 func 时返回 true 为止。换言之,函数的最终返回值也应是一个数组,它由原数组中第一个使得 functrue 的元素及其之后的所有元素组成。

如果数组中的所有元素都不能让 functrue,则返回空数组 []

--hints--

dropElements([1, 2, 3, 4], function(n) {return n >= 3;}) 应返回 [3, 4]

assert.deepEqual(
  dropElements([1, 2, 3, 4], function (n) {
    return n >= 3;
  }),
  [3, 4]
);

dropElements([0, 1, 0, 1], function(n) {return n === 1;}) 应返回 [1, 0, 1]

assert.deepEqual(
  dropElements([0, 1, 0, 1], function (n) {
    return n === 1;
  }),
  [1, 0, 1]
);

dropElements([1, 2, 3], function(n) {return n > 0;}) 应返回 [1, 2, 3]

assert.deepEqual(
  dropElements([1, 2, 3], function (n) {
    return n > 0;
  }),
  [1, 2, 3]
);

dropElements([1, 2, 3, 4], function(n) {return n > 5;}) 应返回 []

assert.deepEqual(
  dropElements([1, 2, 3, 4], function (n) {
    return n > 5;
  }),
  []
);

dropElements([1, 2, 3, 7, 4], function(n) {return n > 3;}) 应返回 [7, 4]

assert.deepEqual(
  dropElements([1, 2, 3, 7, 4], function (n) {
    return n > 3;
  }),
  [7, 4]
);

dropElements([1, 2, 3, 9, 2], function(n) {return n > 2;}) 应返回 [3, 9, 2]

assert.deepEqual(
  dropElements([1, 2, 3, 9, 2], function (n) {
    return n > 2;
  }),
  [3, 9, 2]
);

--seed--

--seed-contents--

function dropElements(arr, func) {
  return arr;
}

dropElements([1, 2, 3], function(n) {return n < 3; });

--solutions--

function dropElements(arr, func) {
  while (arr.length && !func(arr[0])) {
    arr.shift();
  }
  return arr;
}