Given two resource plans, or two generic lists of parent objects, find common ancestor and the relation with them.
This module ESM-exports one function:
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
.
:TODO:
- 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.
ISC