Drop it question

Drop it question
0

#1

Tell us what’s happening:
Can anybody tell me what is wrong with my code? It does’t seem to modify the arrays as I expected.

Your code so far


function dropElements(arr, func) {
  var i = 0;
  function removeElm(arrM, elm) {
   var ind = arrM.indexOf(elm);
   arrM.splice(ind, 1);
   
  }
 while (func===false) {
   for(i = arr.length; i >-1 ; i--) {
     if (func(arr[i])===false) {
       removeElm(arr, arr[i]);
      
     }
   }
   
 }
 console.log("arr is now " + arr);
 return arr[i];
}

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/68.0.3440.106 Safari/537.36.

Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/drop-it/


#2

What is that while doing there? func is a function: if you try to convert it to true or false (which is what that condition is actually doing), it’ll always be true, so nothing inside the while block will ever run. The stuff inside it looks fine at first glance