UNPKG

920 BJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.partitionCycles = exports.getCycle = void 0;
4function getCycle(ancestors, nodeId) {
5 if (!ancestors.includes(nodeId)) {
6 return null;
7 }
8 // first item is where the cycle starts and ends.
9 return ancestors.slice(ancestors.indexOf(nodeId));
10}
11exports.getCycle = getCycle;
12function partitionCycles(nodeId, allCyclesTheNodeIsPartOf) {
13 const cyclesStartWithThisNode = [];
14 const cyclesWithThisNode = [];
15 for (const cycle of allCyclesTheNodeIsPartOf) {
16 const nodeStartsCycle = cycle[0] === nodeId;
17 if (nodeStartsCycle) {
18 cyclesStartWithThisNode.push(cycle);
19 }
20 else {
21 cyclesWithThisNode.push(cycle);
22 }
23 }
24 return { cyclesStartWithThisNode, cyclesWithThisNode };
25}
26exports.partitionCycles = partitionCycles;
27//# sourceMappingURL=cycles.js.map
\No newline at end of file