DEV Community

Discussion on: Code Snippet Series: Remove Junk from Array

Collapse
 
pentacular profile image
pentacular

I suggest that you start by defining a predicate to determine if thing is junk or not.

const isJunk = (thing) => ...;

And since you want to filter on the inverse.

const isNotJunk = (thing) => !isJunk(thing);

Now, you have something meaningful to use with things like filter.

stuff.filter(isNotJunk)