UNPKG

jknife

Version:
2 lines (1 loc) 241 B
function e(e,n=0){const t={},r=[];let d,h;for(h=0;h<e.length;h+=1)t[e[h].id]=h,e[h].children=[];for(h=0;h<e.length;h+=1)d=e[h],d.parentId===n?r.push(d):void 0!==t[d.parentId]&&e[t[d.parentId]].children.push(d);return r}export{e as default};