jadjoubran / codetogo.io

🚀 JavaScript code to go - Find updated snippets for common JavaScript use cases
https://codetogo.io
MIT License
233 stars 30 forks source link

Use Case Suggestion: How to traverse tree in javascript #87

Closed tomastrajan closed 6 years ago

tomastrajan commented 6 years ago

Traversing tree data structure, eg objects with children property recursively to arbitrary depth is useful for interviews and also in practice when implementing with stuff like file explorer or multi level nested menus.

jadjoubran commented 6 years ago

Thanks @tomastrajan for this! Do you happen to have a code example for this? or even pseudo code

tomastrajan commented 6 years ago

Not really but it's about recursively traversing children until the desired element is found.

jadjoubran commented 6 years ago

okay cool 👍 I will research that soon

nicksspirit commented 6 years ago

I don't mind giving this a try. @jadjoubran how many lines of code do you recommend this to be?

jadjoubran commented 6 years ago

Thanks @OdinTech3! Most use cases on CodeToGo are at most 2 to 3 lines of readable javascript code If it turns out to be a complicated method then it's probably better suited for 30-seconds-of-code than codetogo