Intermediate Algorithm Scripting - Drop it test case issue

Tell us what’s happening:
I have issues in two test cases
1)

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

This should return `[1,0,1]` however I am getting `[1,1]` and to be honest I don’t understand why should i get 0 in here logically …shouldn’t we only need to return those n whose value is 1.

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

Here I should be getting `[3,9,2]` but I am getting `[3,9]` again that doesn’t make sense to me logically …aren’t we selecting n that are greater than 2 then why 2 should be in returned list ?

``````function dropElements(arr, func) {
let l=[];
for(let i=0;i<arr.length;i++){
if(func(arr[i])){
l.push(arr[i]);
}

}
console.log(l);
return l;
}

dropElements([1, 2, 3], function(n) {return n < 3; });
dropElements([1, 2, 3, 4], function(n) {return n >= 3;});
dropElements([0, 1, 0, 1], function(n) {return n === 1;});
dropElements([1, 2, 3, 9, 2], function(n) {return n > 2;})
``````

Challenge: Intermediate Algorithm Scripting - Drop it

hi, maybe you need to read instruction few times like me. If still no clue, can look at the pattern of the test case,:

For example:

``````dropElements([1, 2, 3, 9, 2], function(n) {return n > 3;})` should return `[7, 4]` .
``````
``````arr[0] = 1, condition == false
arr[1] = 2, condition == false
arr[2] = 3, condition == true
arr[3] = 9, condition == true
arr[4] = 2, condition == false
``````

Because the “first” true happend at arr[2], so it will be kept, and his following friends also. Therefore returning [3,9,2]

Read this part of the requirements again.

return the rest of the array once the condition is satisfied

That is inclusive so from the element that makes the callback satisfy the condition and the rest of the array.

Can you think of an array method that returns a copy of a portion of an array?

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.