Message from JavaScript discussions
February 2018
— I want to make an algorithm what works with paths though
There are already a few which do certain things with them, and filter
uses them internally to do a post-traversal reconstruction
— But if I made a few that accept paths as arguments, then a search index could also be made of an array of string paths
— Uhmm, array of arrays would be better
—
[
[ 'foo', 'bar', 'prop.with.dots' ]
]
— That's what they are
— Ahh
— I can re-use how filter
reconstructs objects to parse paths into search indexes, something like this
const paths = d.paths({hello: ["friend", "grandma"]});
// parse paths into search index
const search = {};
paths.forEach(function (path, acc) {
var loc = search;
path.forEach(function (prop, acc) {
if (!prop in loc) loc[prop] = acc < path.length ? {} : null;
loc = loc[prop];
});
});
— const paths = paths(...)
? :^)
— Returns an array of arrays of paths
— Oh whoops
— Check out done
module of the strategy https://github.com/Floofies/Differentia.js/blob/master/src/strategies.js#L548