I need help with the Seek and Destroy algorithm challenge

Tell us what’s happening:
Everytime I submit the code below, it returns the array found inside of inner_array. Why is this?
Thanks in advance to all who respond!

Your code so far

function destroyer(arr) {
  var outer_array = Array.from(arguments);
  var inner_array = outer_array.shift();
  var new_array = inner_array.filter(function(val){
      for (var i = 0; i < outer_array.length; i++) {
      if(val != outer_array[i]) {
        return val;
  return new_array;

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

Link to the challenge:

filter expects a Boolean value to be returned from the callback function. If true is returned, the item is kept in the new array (new_array). Your callback function only iterates through outer_array until val !=outer_array[i] evaluates to true, in turn returns val. It the test case of destroyer([1, 2, 3, 1, 2, 3], 2, 3) val will be a number (1, 2, or 3). If you recall from the Falsy Bouncer challenge, any value which is not false, null, 0, “”, undefined, or NaN is considered a truthy value. When you return an number, that is like return the value true, so the current element being iterated on by filter will be present in new_array.

1 Like