I am changing a object twice from and array of objects such that in the first iteration I filter out a few objects and in the second I change each of the filtered objects using map. Can I use reducer or something better?
const originalTree = html.parse(text);
if (originalTree[0].type === 'text') {
return text;
}
const result = originalTree
.map((obj) => ({
...obj,
children: obj.children.filter((el) => el.name !== 'style'),
}))
.map((obj) => ({
...obj,
children: obj.children.map(function(child) {
child.attrs = {};
return child;
}),
}));
return html.stringify(result);
}