Inverse of [].filter in JS?
I realize that I can do:
arr = arr.filter(function(n){ return !filterFunc(n); });
But is there any way to just invert a filter without wrapping the filterer in an anon function?
It just seems cumbersome.
You can use an arrow function:
const a = someArr.filter(someFilter);
const a = someArr.filter(e => !someFilter(e));
Lodash provides a reject function that does the exact opposite of filter.
arr = _.reject(arr, filterFunc);
Take a look at lodash's negate function. It does exactly what @Yury Tarabanko mentions in his comment.
Usage:
arr = arr.filter(_.negate(filterFunc));