Mini linter


My question is for step 3 in this project.

Why does this code not function as intended?

const betterWords = storyWords.filter(word => { if(word !== unnecessaryWords) return word; })

This code returns the storyWords array without filtering the unnecessaryWords.

I have tried this code and it will filter out the words specified manually:

const betterWords = storyWords.filter(word => { if(word !== 'literally') if(word !== 'extremely') if(word !== 'actually') return word; });

Now I have a betterWords array without the words identified above but I understand why this wouldn’t be ideal unless you wanted to add a new unnecessary word to both the variable and the function.

Rather than considering why it doesn’t work, maybe consider why it would work? Things don’t work by default. If I was asking why something isn’t working, I would at the same time feel the need to describe what I think needs to happen according to documentation and describe in what ways I’m fulfilling that and having tested those things - if I’ve checked all those things and still not seeing anything, then it would be a mystery! But you haven’t. Right. So no real reason to have that expectation.
So what does your callback function need to be doing, what input does it receive what output should it produce? Have you read any documentation on filter? Because that would tell you how that callback is expected to behave.
Have you tested your callback by itself without filter, does it behave the way that filter’s documentation describes?
Also, don’t just look at the end result, look at what you did to reach it. The end result isn’t the only thing that is observable.

All those unnecessary assumptions about what I haven’t done or what I have done are not very productive.
I have read the MDN, it is open on my browser at all times.
You, specifically, are the reason I do not post questions on here.

Here is why I assume it should work:
refer to the code that I posted above.

If you, specifically, do not have anything productive or non condescending to post I would very much like for you to keep it to yourself.

If you look at mdn’s description of that callback, it says it should return a boolean. What type does the return value of your function have?

And yeah I’m going to call you out on your methodology when it is the cause. Your code isn’t wrong because you made a mistake, it’s wrong because you didn’t cross your t’s and dot your i’s. These are the things you would look at, and you haven’t.

You may well be stuck. I’m not questioning that!

My post would be condescending if it was pointing out obvious things that you obviously already did. Those are the things that you did wrong. Those are things you can use to approach and solve your problem.

Consider how .filter() works.

const predicate_function = x => x > 0;

is_positive = [1, -1, 2, -2, 3, -3].filter(predicate_function)

Note how the predicate function returns true if x is positive.

Can you think of another iterator that can be used inside your function?