Tell us what’s happening:
Not sure why my code is not passing bellow two conditions of the test:
Round two: dropElements ([0, 1, 0, 1], function(n) {return n === 1;})
My code returns [1,1]. What is wrong with the result?
Round six: dropElements([1, 2, 3, 9, 2], function(n) {return n > 2;})
My code returns [3,9]. What is wrong with the result?
Many thanks in advance.
Your code so far
function dropElements(arr, func) {
let newArr=arr.filter(x=> func(x))
console.log(newArr)
return newArr;
}
dropElements([1, 2, 3, 9, 2], function(n) {return n > 2; });
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.89 Safari/537.36.
I agree one has to read challenge description twice to get it, but challenge asks you to drop only elements before the first successful. Your function drops all unsuccessful elements.
It passes argument to the function that sets the conditions I would say. It then takes result of this function as a condition to filter. Filters out all the elements that fulfill criteria and puts them into new array, It’s actually pretty elegant, I think.
Hi, I am not insisting it does, just saying that it is my understanding of it. It also appears to be working. If there is something I got wrong, I would appreciate your insight.
Thanx.
the arrow points the first element passing the test n === 1 in first case and n > 2 in second case, you should return the array with everything before that element excluded, but that element and everything after included, so you should return [1, 0, 1] and [3, 9, 2]
Instead you are returning [1, 1] and [3, 9], keeping only the elements that pass the test
so, you can’t use the filter method