Seek and Destroy, foor loop not iterating

Seek and Destroy, foor loop not iterating
0.0 0

#1

Tell us what’s happening:

Guys I am trying to figure out why my for loop is not iterating, it just does with the [0]…

Your code so far

function destroyer(arr) {
 var seek=[];
  var destroyed=[];
  var destroy=[];
 var args = Array.prototype.slice.call(arguments); //transforms arr to array.
 seek = args.slice(1); // arguments to check if are present in var destroy
 destroy = arr.slice.call(arguments[0]);   // array with elements that needs to be remove.
    
 destroyed = destroy.filter(function(val){
   
 for (var i=0; i< destroy.length; i++){
      
     if( val != seek[i]){
     
       return true;
   }
   
    return false;
   
            }
  
  
    });
     
   return destroyed;    
  

}

destroyer([1, 2, 3, 1, 2, 3], 2, 3);

Your browser information:

Your Browser User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.186 Safari/537.36.

Link to the challenge:


#2

I found what I was doing wrong, " A for loop should stop only, if a not wanted value is found" So I just changed my code a little bit.

function destroyer(arr) {
 var seek=[];
  var destroyed=[];
  var destroy=[];
 var args = Array.prototype.slice.call(arguments); //transforms arr to array.
 seek = args.slice(1); // arguments to check if are present in var destroy
 destroy = arr.slice.call(arguments[0]);   // array with elements that needs to be remove.
    
 destroyed = destroy.filter(function(val){
   
 for (var i=0; i< destroy.length; i++){
      
     if( val == seek[i]){
     
       return false;
   }
   
            }
  return true;
  
    });
     
   return destroyed;    
  

}

destroyer([1, 2, 3, 1, 2, 3], 2, 3);