search and replace ```\n< with ```\n\n< to ensure there's an empty line before closing tags
2.7 KiB
2.7 KiB
id, title, isRequired, challengeType, videoUrl, localeTitle
id | title | isRequired | challengeType | videoUrl | localeTitle |
---|---|---|---|---|---|
a5deed1811a43193f9f1c841 | Drop it | true | 5 | 算了吧 |
Description
arr
,迭代并从第一个元素(0索引)开始删除每个元素,直到函数func
在迭代元素通过它时返回true
。然后在条件满足后返回数组的其余部分,否则, arr
应作为空数组返回。如果卡住,请记得使用Read-Search-Ask 。尝试配对程序。编写自己的代码。 Instructions
Tests
tests:
- text: '<code>dropElements([1, 2, 3, 4], function(n) {return n >= 3;})</code>应该返回<code>[3, 4]</code> 。'
testString: assert.deepEqual(dropElements([1, 2, 3, 4], function(n) {return n >= 3;}), [3, 4]);
- text: '<code>dropElements([0, 1, 0, 1], function(n) {return n === 1;})</code>应该返回<code>[1, 0, 1]</code> <code>dropElements([0, 1, 0, 1], function(n) {return n === 1;})</code> <code>[1, 0, 1]</code> 。'
testString: assert.deepEqual(dropElements([0, 1, 0, 1], function(n) {return n === 1;}), [1, 0, 1]);
- text: '<code>dropElements([1, 2, 3], function(n) {return n > 0;})</code>应该返回<code>[1, 2, 3]</code> 。'
testString: assert.deepEqual(dropElements([1, 2, 3], function(n) {return n > 0;}), [1, 2, 3]);
- text: '<code>dropElements([1, 2, 3, 4], function(n) {return n > 5;})</code>应返回<code>[]</code> 。'
testString: assert.deepEqual(dropElements([1, 2, 3, 4], function(n) {return n > 5;}), []);
- text: '<code>dropElements([1, 2, 3, 7, 4], function(n) {return n > 3;})</code>应该返回<code>[7, 4]</code> <code>dropElements([1, 2, 3, 7, 4], function(n) {return n > 3;})</code> <code>[7, 4]</code> 。'
testString: assert.deepEqual(dropElements([1, 2, 3, 7, 4], function(n) {return n > 3;}), [7, 4]);
- text: '<code>dropElements([1, 2, 3, 9, 2], function(n) {return n > 2;})</code>应该返回<code>[3, 9, 2]</code> <code>dropElements([1, 2, 3, 9, 2], function(n) {return n > 2;})</code> <code>[3, 9, 2]</code> 。'
testString: assert.deepEqual(dropElements([1, 2, 3, 9, 2], function(n) {return n > 2;}), [3, 9, 2]);
Challenge Seed
function dropElements(arr, func) {
// Drop them elements.
return arr;
}
dropElements([1, 2, 3], function(n) {return n < 3; });
Solution
// solution required
/section>