JSFiddle - React, Tailwind, and code Playground
by brigand
JavaScript
// The tree.
const tree = [{
cl: "wrapper",
pr: null,
el: func_a
}, {
cl: "left",
pr: "wrapper",
el: func_b
}];
// What am I doing wrong to iterate through the tree?
const iter = (items, pr = null) => {
return items.filter(item => item.pr === pr)
.map(item => ({
...item,
children: iter(items, item.cl)
}))
}
iter(tree)