walker? idk

This commit is contained in:
Seth Trowbridge 2025-03-06 13:53:00 -05:00
parent 869b406323
commit 342ca8c5fc

View File

@ -1,34 +1,39 @@
const set = new Set();
function Walk(obj, parentObject, propertyName, path=[])
function Walk(obj)
{
if(obj !== null && typeof obj === "object")
const set = new Set();
function Step(obj, path="")
{
if(set.has(obj))
if(obj !== null && typeof obj === "object")
{
console.log("ive been to", obj, "quitting");
return;
if(set.has(obj))
{
console.log("ive been to", obj, "quitting");
return;
}
else
{
set.add(obj);
console.log("ive never seen", obj, "here are its fields:");
console.log("-----------------");
for(let key in obj)
{
const val = obj[key];
console.log(" >stepping into", path+"."+key);
Step(val, path+"."+key);
}
console.log("-----------------");
}
}
else
{
set.add(obj);
console.log("ive never seen", obj, "here are its fields:");
console.log("-----------------");
for(let key in obj)
{
const val = obj[key];
console.log(key, val);
Walk(val, obj, key);
}
console.log("-----------------");
console.log(obj, "is a leaf");
}
}
else
{
console.log(obj, "is a leaf")
}
Step(obj);
}
const root = {hey:"1", deep:{}, arr:["a", "b"]};
const root = {hey:"1", deep:{basement:{closet:{item1:"one", item2:"two"}}}, arr:["a", "b"]};
root.circ = root;
Walk(root);