中級のアルゴリズムスクリプト - ドロップする

hallo. i have a question.

For this task I have written the code as described below.

function dropElements(arr, func) {
return arr.filter(func);
}

but this two condition was not filled

dropElements([0, 1, 0, 1], function(n) {return n === 1;}) should return [1, 0, 1] .

dropElements([1, 2, 3, 9, 2], function(n) {return n > 2;}) should return [3, 9, 2]

I can not understand why I doesn’t work.
could you please explain?

現状のコード

function dropElements(arr, func) {
  return arr.filter(func);
}

dropElements([1, 2, 3], function(n) {return n < 3; });

ブラウザ情報:

ユーザーエージェント: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.1 Safari/605.1.15

チャレンジの情報:

中級のアルゴリズムスクリプト - ドロップする

your code removes all elements that don’t match the condition, but instead read more carefully the description, you need to stop removing elements when you find the first element that returns true with the condition, and return the rest of the array unchanged

1 Like