Created
June 7, 2021 04:51
-
-
Save janaki-sasidhar/eccda0bc2b997103e617fa58efad2593 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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