Skip to content

Instantly share code, notes, and snippets.

@c01nd01r c01nd01r/filters.es6.js
Last active Apr 8, 2017

Embed
What would you like to do?
multiple array filters with functions
const data = [
{id: 1, total: 9, type: 'cashout'},
{id: 2, total: 8, type: 'cashin'},
{id: 3, total: 5, type: 'cashout'},
{id: 4, total: 4, type: 'cachin'},
{id: 5, total: 3, type: 'cashout'},
];
const filters = {
total(val) {
return val.total > 4;
},
type(val) {
return val.type === 'cashout';
},
};
const filteredData = data.filter( item =>
Object.keys(filters).every(filterIdx => filters[filterIdx](item))
);
console.log('result:', filteredData)
// result: Array(2)
// [
// {id:1, total: 9, type: 'cashout'},
// {id:3, total: 5, type: 'cashout'},
// ]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.