@wordpress/block-library
Version:
Block library for the WordPress editor.
23 lines (22 loc) • 443 B
JavaScript
const convertToTree = (data) => {
const table = {};
if (!data) {
return [];
}
data.forEach((item) => {
table[item.id] = { commentId: item.id, children: [] };
});
const tree = [];
data.forEach((item) => {
if (item.parent) {
table[item.parent]?.children.push(table[item.id]);
} else {
tree.push(table[item.id]);
}
});
return tree;
};
export {
convertToTree
};
//# sourceMappingURL=util.js.map