Q:

Filter array of objects by array of objects [TypeScript] [ES6]

How to filter array of objects by array of objects with conditions.
Interfaces:
interface Person {
    age: number;
    available: boolean;
}

interface PersonFilter {
    predicateFn(arg: Person): boolean;
}

Data: 
const persons = [
  {
    "age": 2,
    "available": false
  },
  {
    "age": 5,
    "available": true
  }
];

Conditions to filter:
const filters = [
    {predicateFn: person => person.available},
    {predicateFn: people => person.age > 2}
];

How to filter this array of objects using current filters structure ?
function getFilteredPersons(filters): Person[]{
return persons.filter( ?? );
}    

Expected output:
  [
      {
        "age": 5,
        "available": true
      }
    ]

A:

You can try it with the Array.prototype.every function, it would be something like:

const persons = [{
    age: 2,
    available: false
  },
  {
    age: 5,
    available: true
  }
];

const filters = [{
    predicateFn: person => person.available
  },
  {
    predicateFn: person => person.age > 2
  }
];

function getFilteredPersons(filters) {
  return persons.filter(p => filters.every(filter => filter.predicateFn(p)));
}

console.log(getFilteredPersons(filters));

