ancestor
find the lowest common ancestor in a directed, acyclic graph
Last updated 7 years ago by mirkok .
BSD · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install ancestor 
SYNC missed versions from official npm registry.

#Most recent common ancestor an implementation in javascript.

var findAncestor = require('ancestor')

var nodes = {
  1: [],
  2: [1],
  3: [2],
  4: [2],
  5: [4],
  6: [3, 5],
  7: [6],
  8: [5],
  9: [8]
}

/* the graph:

    4-5-8-9   
   /   \
1-2-3---6-7

*/

var readParents = function(id) {
  return nodes[id]
}

var result = findAncestor([9, 7], readParents)
// returns:
5

Current Tags

  • 0.1.3                                ...           latest (7 years ago)

4 Versions

  • 0.1.3                                ...           7 years ago
  • 0.1.2                                ...           7 years ago
  • 0.1.0                                ...           7 years ago
  • 0.0.1                                ...           7 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 4
Dependencies (2)
Dev Dependencies (1)

Copyright 2014 - 2016 © taobao.org |