Skip to content

Recursively find and return a nested node and all its ancestors (parents) from a nested data structure (i.e. tree)

License

Notifications You must be signed in to change notification settings

alferov/find-ancestors

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

39 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

find-ancestors

Recursively find and return a nested node and all its ancestors (parents) from a nested data structure (i.e. tree)

Install

$ npm install --save find-ancestors

Usage

var findAncestors = require('find-ancestors');

var tree = [{
  id: 1,
  children: [{
    id: 2
  }, {
    id: 3
  }]
}];

findAncestors(tree, function(item) {
  return item.id === 3;
}); // => [{ id: 3 }, { id: 1, children: [{ id: 2 }, { id: 3 }] }]

API

findAncestors(options)

Recursively find and return a nested node and all its ancestors (parents) from a nested data structure (i.e. tree)

Params

  • Array data: An array of data
  • Function predicate: A filter criteria

Return

  • Array: Matched node and its ancestors

License

MIT © Philipp Alferov

About

Recursively find and return a nested node and all its ancestors (parents) from a nested data structure (i.e. tree)

Resources

License

Stars

Watchers

Forks

Packages

No packages published