Refactor and more linking

This commit is contained in:
Dunemask 2022-08-12 13:08:00 +00:00
parent f17c7e01f5
commit 2db11ac3dd
24 changed files with 197 additions and 177 deletions

View file

@ -1,31 +0,0 @@
import _ from "lodash";
const nest = (arr) => {
const obj = {};
arr.reduce((o, s) => (o[s] = {}), obj);
return obj;
};
export const asTree = (branches) => {
const nests = branches.map((b) => nest(b));
return _.merge(...nests);
};
export const asBranches = (array) => {
const merged = [];
array.forEach((p, i) => {
p.forEach((v, i) => {
if (!merged[i]) merged[i] = [];
if (!merged[i].includes(v)) merged[i].push(v);
});
});
return merged;
};
export const as1d = (a) => [].concat.apply([], a);
export const selectBranch = (map, test) => {
const pipeline = map.find((pm) => pm.includes(test));
const testIndex = pipeline.findIndex((t) => t === test);
return pipeline.slice(0, testIndex + 1);
};