New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

iterate-tree

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

iterate-tree

iterate tree structure using Depth-first search(DFS) and Breadth-first search(BFS) algorithms for traversing or searching

  • 2.0.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
12
decreased by-78.95%
Maintainers
1
Weekly downloads
 
Created
Source

iterate-tree

npm

Iterate tree object by given propety name and callback.

Methods implement Depth-first search(DFS) and Breadth-first search(BFS) algorithms for traversing or searching.

Install

npm install iterate-tree

Traversing

var iterator = require('iterate-tree')

//Breadth-first search(BFS)
iterator.bfs(treeObject, 'propName', (obj) => {

    // Do something with the object

});

//Depth-first search(DFS)
iterator.dfs(treeObject, 'propName', (obj) => {

    // Do something with the object

});

Searching

If method is used as search of an object in the tree structure - RETURN FALSE in the callback breaks the search when it is needed.

var iterator = require('iterate-tree')

//Breadth-first search(BFS)
iterator.bfs(treeObject, 'propName', (obj) => {
    if(obj == condition){
        
        // Do something with the found object

        return false; // finish the search
    }
});

//Depth-first search(DFS)
iterator.dfs(treeObject, 'propName', (obj) => {
    if(obj == condition){
        
        // Do something with the found object

        return false; // finish the search
    }
});

Keywords

FAQs

Package last updated on 14 Nov 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc