Seek and Destroy. Here's my code so far

Tell us what’s happening:
I’m trying to delete the numbers in the array that equals to the numbers out of the array.

Your code so far

 function destroyer(arr) {
     let args = [];
     for(let i = 0; i < args.length; i++) {
         for(let j = 0; j < args[i].length; j++) {
           if(args[i][j] === args[i]) {
             delete args[i][j];
         return args[0];

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

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.99 Safari/537.36.

Link to the challenge:


args is equal to [ [ 1, 2, 3, 1, 2, 3 ], 2, 3 ] Are you sure that’s what you want to loop over in your outer loop?
I suggest that you break out the arguments into named variables at least during testing to make them easier to keep up with.

delete does remove an element from the array but it leaves a hole filled with undefined

You might do better to create an results array and push the ‘keeper’ elements onto that as opposed to removing items from an array.

Good luck

Your if statement (below) is trying to compare an element of array arr[i] with the array itself arr[i]. That will always be false, because arrays can never be equal to numbers or strings.

See the following modification of your code, so you can see the values of the variables and comparisons you are making while the code runs. You will notice that your code never makes it past i = 0, because you return args[0] inside the outer for loop, which causes the function to exit immediately.

1 Like