My solution for "Seek and Destroy"

I wrote another blog post, this time about how I solved the “Seek and Destroy” JavaScript Coding Challenge.

I really hope this will be useful for the community!
If you have any questions or concerns, let me know and I’d be happy to help! :grinning:

No .reduce()??? Disliked, blocked, unfollowed :unamused:

Also have you heard the word of our lord and savior ... (i.e. rest operator)?

function destroyer(arr, ...rest) {
  return arr.filter(n => !rest.includes(n))
}

(I know it says you have to use arguments, but it’s not enforced :grin:)

1 Like

Yeah… I followed the rules. I’m not a felon!! :laughing:

Hmm… I forgot about the includes… my bad. Thanks for the addition @jenovs! Great as always! :smiley: except that you are breaking the rules! :cough: :upside_down_face:

function destroyer() {
  const [arr, ...rest] = arguments;
  return arr.filter(n => !rest.includes(n))
}

Better?

1 Like

Hmm… nope. I think my solution is better. Check this out:

const destroyer = (arr, ...rest) =>
    arr.reduce(
        (acc, curr) => (!rest.includes(curr) ? [...acc, curr] : acc),
        []
    );

So good that I think I have to update the blog post and add it! :laughing:

1 Like

@camperextraordinaire sure, I’ll do that! :slight_smile: