I need to filter an array based an a variable number of items in another array. Say my array to be filtered looks like this :
var toBeFiltered = [
{name:"A", parentId: 0},
{name: "B", parentId: 3},
{name: "C", parentId: 0},
{name: "D", parentId: 1},
...
]
I need to filter all the elements for which parentId is in another array (say : var filtering = [3,1,0], but it can have any length).
How can I build a filter expression dynamically based on the content of the filtering array ? In this case I'd end up with this expression :
function(d){return d.parentId == 3 || d.parentId == 1 || d.parentId == 0;}
Is there any smart way to do this ? Something like concatenation of boolean expressions ?