JS/TS Tree Higher Order Functions
- Adds big value to your project, because tree algorithms can be challenging to get right easily.
- Wanted to create an easy to use, generic tree traversal library.
- Felt the existing ones were not complete.
- Need easy tree traversal in many projects.
- Wanted to prove to myself that I can implement these recursive algorithms.
- Simple tree to array transformers.
- Breadth first traversal.
- All depth first traversals (pre-/in-/post- order).
- NO Iterators. Higher order functions make for loops obsolete. Just use
Array.forEachif you have to and
- Just over 6KB unminified! 2.8KB minified!
If you have tried this before and it didn't work, please try again. It should now be working. It has no dependencies and I believe adds a lot of value while being very small.
This has been tested with binary trees only but should work with any number of children. There are unit tests.
The example above is in TypeScript only at the moment. However, it should also work with vanilla JS or any library.