1.7 KiB
1.7 KiB
id, title, challengeType, forumTopicId
id | title | challengeType | forumTopicId |
---|---|---|---|
a5deed1811a43193f9f1c841 | 筛选出数组中满足条件的元素 | 5 | 16010 |
--description--
给定数组arr
,从数组的第一个元素开始,用函数func
来检查数组的每个元素并删除,直到某个元素传入函数func
时返回true
。函数最终的返回值也是一个数组,它由原数组中第一个使得func
为true
的元素及其之后的所有元素组成。
如果数组中的所有元素都不能让func
为true
,则返回空数组[]
。
--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]
);