For further actions, you may consider blocking this person and/or reporting abuse
Read next
Building a Self-Evolving Codebase: JavaScript’s AST Manipulation and Dynamic Compilation
Shafayet Hossain -
11 GitHub Repositories to learn NodeJs
Shefali -
Exploring JavaScript's Modern Primitives: BigInt and Symbol
Joan Peramás Ceras -
🎨 Top 10 Must-Have Icon Libraries for Next.js in 2024
Hamza Khan -
Top comments (2)
Because what you have here is a doubly linked tree, you have a choice how you want to populate the tree. I think it would be easier attaching children to their parents.
What I would do is:
children
(it's because the name childrenID suggest, that it has something to do with ID, not the children themselves)parentID
from the lookup map and push it at the end of thechildren
arrayparentID: null
. You could use.filter
for this.For better efficiency, you could bundle points 2, 3 and 4 into one.
Good luck!
I FOUND A SOLUTION - jsfiddle.net/cw9rq7ht/6/