Seek and Destroy - does my solution resemble functional programming?

Hey people,

I really like FP. After completing OOP which seemed like a big mess to me, FP is like a wave of fresh water. I love the concept, I love the straightforwardness of it but I am also aware that I know very little about it yet.
I’ve had this challenge in front of my eyes for a few minutes and started to think it out in chunks (algorithm after all, huh?) and to my great surprise the solution came out pretty easy and it worked. I then looked at various solutions on this forum and in the guide and got some seconds thoughts, My main concern is how re-usable is this? Does spread operator and filter function do the right job?

function destroyer(arr) {
  // Remove all the values
  return arr.filter(x => !([...arguments].includes(x)));

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

Link to the challenge.

Looks perfect, only thing I would do is move the spreading of the arguments into the funtion head as a parameter to make it more explicit.

function destroyer(arr, ...targets) {
  return arr.filter(x => !targets.includes(x))
1 Like