Skip to content

Instantly share code, notes, and snippets.

@janaki-sasidhar
Created June 7, 2021 04:51
Show Gist options
  • Save janaki-sasidhar/eccda0bc2b997103e617fa58efad2593 to your computer and use it in GitHub Desktop.
Save janaki-sasidhar/eccda0bc2b997103e617fa58efad2593 to your computer and use it in GitHub Desktop.
const multiFilter = (A,F) => {
const filterkeys = Object.keys(F);
return A.filter(eachObj => {
return filterkeys.every(eachKey => {
console.log('hi')
if(!F[eachKey].length){
return true // ignore filter and return all
}
return eachObj[eachKey].includes(F[eachKey])
})
})
}
full_data = [
{
'name':'sasidhar',
'last' : 'janaki'
},
{
'name': 'sasidhar2',
'last':'janaki2'
},
{
'name':'bharath',
'last': 'anonymous'
}
]
partial_data = {
'name':'',
'last': ''
}
console.log(multiFilter(full_data,partial_data))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment