2018-10-10 18:03:03 -04:00
---
id: a5deed1811a43193f9f1c841
title: Drop it
isRequired: true
challengeType: 5
2019-08-28 16:26:13 +03:00
forumTopicId: 16010
2018-10-10 18:03:03 -04:00
localeTitle: Брось это
---
## Description
2019-08-28 16:26:13 +03:00
< section id = 'description' >
2019-11-19 19:54:48 -05:00
Учитывая массив < code > arr< / code > , выполните итерацию и удаление каждого элемента, начиная с первого элемента (индекс 0) до тех пор, пока функция < code > func< / code > вернет < code > true< / code > когда итерационный элемент пройдет через него. Затем возвращаем остальную часть массива после выполнения условия, иначе < code > arr< / code > должен быть возвращен как пустой массив. Н е забудьте использовать < a href = "https://www.freecodecamp.org/forum/t/how-to-get-help-when-you-are-stuck-coding/19514" target = "_blank" > Read-Search-Ask,< / a > если вы застряли. Попробуйте подключить программу. Напишите свой собственный код.
2019-08-28 16:26:13 +03:00
< / section >
2018-10-10 18:03:03 -04:00
## Instructions
2019-08-28 16:26:13 +03:00
< section id = 'instructions' >
2018-10-10 18:03:03 -04:00
< / section >
## Tests
< section id = 'tests' >
```yml
tests:
2019-08-28 16:26:13 +03:00
- text: < code > dropElements([1, 2, 3, 4], function(n) {return n >= 3;})</ code > should return < 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 > should return < 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 > should return < 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 > should return < 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 > should return < 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 > should return < code > [3, 9, 2]</ code > .
testString: assert.deepEqual(dropElements([1, 2, 3, 9, 2], function(n) {return n > 2;}), [3, 9, 2]);
2018-10-10 18:03:03 -04:00
```
< / section >
## Challenge Seed
< section id = 'challengeSeed' >
< div id = 'js-seed' >
```js
function dropElements(arr, func) {
// Drop them elements.
return arr;
}
dropElements([1, 2, 3], function(n) {return n < 3 ; } ) ;
```
< / div >
< / section >
## Solution
< section id = 'solution' >
```js
2019-08-28 16:26:13 +03:00
function dropElements(arr, func) {
// Drop them elements.
while (arr.length & & !func(arr[0])) {
arr.shift();
}
return arr;
}
2018-10-10 18:03:03 -04:00
```
2019-08-28 16:26:13 +03:00
2018-10-10 18:03:03 -04:00
< / section >