I have an array with multilevel objects, such as:
list= [ {
type: { name: 'dog', size:'medium'},
entity: { name: 'Tobby', age: '7'},
},
{
type: { name: 'cat', size:'small'},
entity: { name: 'Garfield', age: '7'},
}
]
And I have a defined filter such as:
filter={
type: { name:'dog'}}
I need to define a function such that I can call
let filtered = list.thisMagicFilter(filter)
that will filter accordingly on my list (in the given example, returning only the first element.
Logically, if the filter is {entity:{age:'7'}}, then both results should be returned.
I've broken my head trying to do this in a functional programming with a list.filter(), but it's just too complex for me: I'm struggling on the fact that it's a 2 level validation.
Can I get some hint of how to tackle this problem?
Thank you in advance!