Seek & Destroy returns blank array

Array returns blank, I’ve been trying to see the problem (for 30 minutes) but I guess I don’t have the eye for it yet!


//GOAL: erase all destroyer[1, 2] values in destroyer[0]

function destroyer(array) {

//filter non-targeted elements into a new array and then return it.

var x = array[1];
var y = array[2];

var new_arr = [];

for (var p = 0; p < array[0].length; p++) {
    new_arr = array.filter(function anon() {
        return (x !== array[0][p] && y !== array[0][p]);
    });
}

return new_arr;
}

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

a few problems here. to start with array only refers to the first argument. if you console array you’ll just get [1, 2, 3, 1, 2, 3] and you have no access to 2,3. change the arguments list to include 2nd & 3rd arguement (and more for later tests). Check out Arguments object on MDN

1 Like