2018-10-04 14:37:37 +01:00
---
id: a5deed1811a43193f9f1c841
title: Drop it
challengeType: 5
2019-07-31 11:32:23 -07:00
forumTopicId: 16010
2018-10-04 14:37:37 +01:00
---
2020-11-27 19:02:05 +01:00
# --description--
2018-10-04 14:37:37 +01:00
2020-11-27 19:02:05 +01: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.
Then return the rest of the array once the condition is satisfied, otherwise, `arr` should be returned as an empty array.
# --hints--
`dropElements([1, 2, 3, 4], function(n) {return n >= 3;})` should return `[3, 4]` .
```js
assert.deepEqual(
dropElements([1, 2, 3, 4], function (n) {
return n >= 3;
}),
[3, 4]
);
2018-10-04 14:37:37 +01:00
```
2020-11-27 19:02:05 +01:00
`dropElements([0, 1, 0, 1], function(n) {return n === 1;})` should return `[1, 0, 1]` .
2018-10-04 14:37:37 +01:00
2020-11-27 19:02:05 +01:00
```js
assert.deepEqual(
dropElements([0, 1, 0, 1], function (n) {
return n === 1;
}),
[1, 0, 1]
);
```
2018-10-04 14:37:37 +01:00
2020-11-27 19:02:05 +01:00
`dropElements([1, 2, 3], function(n) {return n > 0;})` should return `[1, 2, 3]` .
2018-10-04 14:37:37 +01:00
```js
2020-11-27 19:02:05 +01:00
assert.deepEqual(
dropElements([1, 2, 3], function (n) {
return n > 0;
}),
[1, 2, 3]
);
```
2018-10-04 14:37:37 +01:00
2020-11-27 19:02:05 +01:00
`dropElements([1, 2, 3, 4], function(n) {return n > 5;})` should return `[]` .
```js
assert.deepEqual(
dropElements([1, 2, 3, 4], function (n) {
return n > 5;
}),
[]
);
2018-10-04 14:37:37 +01:00
```
2020-11-27 19:02:05 +01:00
`dropElements([1, 2, 3, 7, 4], function(n) {return n > 3;})` should return `[7, 4]` .
2018-10-04 14:37:37 +01:00
2020-11-27 19:02:05 +01:00
```js
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;})` should return `[3, 9, 2]` .
```js
assert.deepEqual(
dropElements([1, 2, 3, 9, 2], function (n) {
return n > 2;
}),
[3, 9, 2]
);
```
# --seed--
2018-10-04 14:37:37 +01:00
2020-11-27 19:02:05 +01:00
## --seed-contents--
2018-10-04 14:37:37 +01:00
2020-11-27 19:02:05 +01:00
```js
function dropElements(arr, func) {
return arr;
}
2018-10-04 14:37:37 +01:00
2020-11-27 19:02:05 +01:00
dropElements([1, 2, 3], function(n) {return n < 3 ; } ) ;
```
2018-10-04 14:37:37 +01:00
2020-11-27 19:02:05 +01:00
# --solutions--
2018-10-04 14:37:37 +01:00
```js
function dropElements(arr, func) {
while (arr.length & & !func(arr[0])) {
arr.shift();
}
return arr;
}
```