assertthat
Version:
assertthat provides fluent TDD.
25 lines (24 loc) • 785 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.dispelArray = void 0;
const dispel_1 = require("./dispel");
const Recursion_1 = require("../types/Recursion");
const dispelArray = function (value, path = '/', ancestors = []) {
for (const ancestor of ancestors) {
if (value === ancestor.reference) {
return (0, Recursion_1.recursion)({
recursionPath: ancestor.path
});
}
}
const newAncestors = [
...ancestors,
{
reference: value,
path
}
];
const dispelledArray = value.map((subValue, index) => (0, dispel_1.dispel)(subValue, `${path}${index}/`, newAncestors));
return dispelledArray;
};
exports.dispelArray = dispelArray;