Let's say I have a simple array and each index of the array has several properties. What I would like to do is filter the array but be able to reverse the filter back to its normal state so I can apply other filters based on the original array without calling the database again to either get the original state or apply the filter(s) I want. Also note that I don't want to install a 3rd party package so let's try to act like that is not an option.
If have tried stuff like:
Code: Select all
var negate = function(cb) {
return function() {
return !cb.apply(this,arguments);
}
};
var myFilter = function(m) {
return m.someProp === "someString";
};
function applyFilter() {
myArray.filter(myFilter);
}
function revertFilter() {
myArray.filter(negate(myFilter));
}