ubborg-lineage-find-common-ancestor-pmb
v1.0.1
Published
Given two resource plans, or two generic lists of parent objects, find common ancestor and the relation with them.
Downloads
2
Readme
ubborg-lineage-find-common-ancestor-pmb
Given two resource plans, or two generic lists of parent objects, find common ancestor and the relation with them.
API
This module ESM-exports one function:
cmp(a, b)
Where a
and b
each are either
- an Array-like list of generic parent objects,
- an Array-like list of strings,
- or something with a
.traceParents
method that returns any of the above.
Returns an object with these keys:
ancestor
: The lowest common ancestor, offalse
if none was found.common
: The shared prefix of both lists. Empty list if they have no common ancestor.subA
/subB
: List of the steps fromancestor
toa
/b
. Empty list if one of both is found to be an ancestor of the other, ora
isb
.
Usage
:TODO:
Known issues
- Stringification assumes a left-to-right writing system. Let's hope Unicode will some day introduce semantic arrows, which can show direction relative to the direction of the writing system.
- Needs more/better tests and docs.
License
ISC