2018-10-10 18:03:03 -04:00
---
id: a5deed1811a43193f9f1c841
2021-02-06 04:42:36 +00:00
title: Drop it
2018-10-10 18:03:03 -04:00
challengeType: 5
2020-09-07 16:10:29 +08:00
forumTopicId: 16010
2021-01-13 03:31:00 +01:00
dashedName: drop-it
2018-10-10 18:03:03 -04:00
---
2020-12-16 00:37:30 -07:00
# --description--
2018-10-10 18:03:03 -04:00
2021-02-06 04:42:36 +00:00
Given the array `arr` , iterate through and remove each element starting from the first element (the 0 index) until the function `func` returns `true` when the iterated element is passed through it.
2018-10-10 18:03:03 -04:00
2021-02-06 04:42:36 +00:00
Then return the rest of the array once the condition is satisfied, otherwise, `arr` should be returned as an empty array.
2018-10-10 18:03:03 -04:00
2020-12-16 00:37:30 -07:00
# --hints--
2018-10-10 18:03:03 -04:00
2021-02-06 04:42:36 +00:00
`dropElements([1, 2, 3, 4], function(n) {return n >= 3;})` should return `[3, 4]` .
2018-10-10 18:03:03 -04:00
```js
2020-12-16 00:37:30 -07:00
assert.deepEqual(
dropElements([1, 2, 3, 4], function (n) {
return n >= 3;
}),
[3, 4]
);
```
2018-10-10 18:03:03 -04:00
2021-02-06 04:42:36 +00:00
`dropElements([0, 1, 0, 1], function(n) {return n === 1;})` should return `[1, 0, 1]` .
2020-12-16 00:37:30 -07:00
```js
assert.deepEqual(
dropElements([0, 1, 0, 1], function (n) {
return n === 1;
}),
[1, 0, 1]
);
2018-10-10 18:03:03 -04:00
```
2021-02-06 04:42:36 +00:00
`dropElements([1, 2, 3], function(n) {return n > 0;})` should return `[1, 2, 3]` .
2020-12-16 00:37:30 -07:00
```js
assert.deepEqual(
dropElements([1, 2, 3], function (n) {
return n > 0;
}),
[1, 2, 3]
);
```
2018-10-10 18:03:03 -04:00
2021-02-06 04:42:36 +00:00
`dropElements([1, 2, 3, 4], function(n) {return n > 5;})` should return `[]` .
2018-10-10 18:03:03 -04:00
2020-12-16 00:37:30 -07:00
```js
assert.deepEqual(
dropElements([1, 2, 3, 4], function (n) {
return n > 5;
}),
[]
);
```
2018-10-10 18:03:03 -04:00
2021-02-06 04:42:36 +00:00
`dropElements([1, 2, 3, 7, 4], function(n) {return n > 3;})` should return `[7, 4]` .
2018-10-10 18:03:03 -04:00
2020-12-16 00:37:30 -07:00
```js
assert.deepEqual(
dropElements([1, 2, 3, 7, 4], function (n) {
return n > 3;
}),
[7, 4]
);
```
2018-10-10 18:03:03 -04:00
2021-02-06 04:42:36 +00:00
`dropElements([1, 2, 3, 9, 2], function(n) {return n > 2;})` should return `[3, 9, 2]` .
2020-09-07 16:10:29 +08:00
2018-10-10 18:03:03 -04:00
```js
2020-12-16 00:37:30 -07:00
assert.deepEqual(
dropElements([1, 2, 3, 9, 2], function (n) {
return n > 2;
}),
[3, 9, 2]
);
2018-10-10 18:03:03 -04:00
```
2020-08-13 17:24:35 +02:00
2021-01-13 03:31:00 +01:00
# --seed--
## --seed-contents--
```js
function dropElements(arr, func) {
return arr;
}
dropElements([1, 2, 3], function(n) {return n < 3 ; } ) ;
```
2020-12-16 00:37:30 -07:00
# --solutions--
2021-01-13 03:31:00 +01:00
```js
function dropElements(arr, func) {
while (arr.length & & !func(arr[0])) {
arr.shift();
}
return arr;
}
```