...
/Adding False Functionality to Filtering
Adding False Functionality to Filtering
Learn how to extend a generic filter function to explicitly sort by truthy or falsy values.
We'll cover the following...
So far, our function explicitly filters on properties that return a truthy value. But, what if we want the opposite behavior, specifically filtering for properties that are falsy
? For example, we might be maintaining a data type similar to IWidget
and want to find widgets that don’t have a title or description.
Let’s extend our genericFilter
function to handle this use case. Similar to how we added a descending and ascending flag to genericSort
, we’ll need to include an isTruthySelected
flag to genericFilter
, which will trigger the opposite behavior of our existing function. Again, filtering adds additional complexity. Unlike the isDescending
global flag we could pass to genericSort
...