Tell us what’s happening:
I’m doing this challenge linked below.
When second element of array goes through loop it does not shift out of the array and I don’t understand why.
when n>=4 it does shift, but the third one does not.
Your code so far
function dropElements(arr, func) {
let changed = false;
for(let el of arr) {
//console.log(arr);
if(!func(el)) {
//console.log("shifted");
arr.shift();
changed = true;
} else if(changed) return arr;
}
return arr;
}
console.log(dropElements([1, 2, 3], function(n) {return n >= 3;}));
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.142 Safari/537.36
.
Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/drop-it