Confused? Seek and destroy algorithm

Hey guys,
I managed to solve this algorithm challenge but I don’t understand how this code works?
If someone could break it down for me to understand, it would be much appreciated :smile:

You wrote it, so why don’t you walk us through what you were trying to do and how you expected it to behave, and we can help fill in the holes?

I wanted to use the arguments method to find the arguments outside of the array.
Then I used the filter method to create a new array if ‘begone’ can be found in ‘num’, and I think I wanted to return the array if the argument was true.
What I don’t understand is why the empty return statement allows the code to run?

The line below:


returns undefined as a value. It is if would have been written:

  return undefined;

and the same as not returning anything . If nothing is returned from a function, then JavaScript still returns undefined.

Whether or not you put that 2nd return statement or not is irrelevant, because the first return

  return arr.filer(function(num){

is actually going to return the final value. The single return; will never execute.

1 Like

Ok, thank you, I understand it better now.