Tell us what’s happening:
Hi everyone. I’ve solved this challenge a few different ways, but in these two cases I fail to explaine them. How is it that I can use func here, without passing a parameter? Would that not be “undefined”? How does the code know what to put into “n” in func?.
And then there is the while loop. How does the loop know where to look? Does it take the first argument which happens to be the array? To me the loop just says: while 1, shift the array. But 1 where?
I hope that makes sence
Thank you
Your code so far
function dropElements(arr, func) {
// Drop them elements.
if (arr.findIndex(func) < 0) {
return [];
} else {return arr.slice(arr.findIndex(func))};
/*
// Using shift
while (arr.findIndex(func) ) {
arr.shift();
}
return arr
*/
}
dropElements([0,1,0,1], function(n) {return n === 1;});
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.102 Safari/537.36
.
Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/drop-it