Skip to content

Instantly share code, notes, and snippets.

@marekdano
Created September 7, 2018 09:19
Show Gist options
  • Save marekdano/5faad83fbd46bfc1a5df8a3beb8cc7f8 to your computer and use it in GitHub Desktop.
Save marekdano/5faad83fbd46bfc1a5df8a3beb8cc7f8 to your computer and use it in GitHub Desktop.
const flatten = filter => {
const filters = filter.filters;
if (filters) {
return filters.reduce((acc, curr) => acc.concat(curr.filters ? flatten(curr) : [curr]), []);
}
return [];
};
const rootFilters = {
filters: [
{
filters: [{ value: 'test1' }]
},
{
filters: [
{
filters: [{ value: 'test2' }]
}
]
}
]
};
flatten(rootFilters);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment