walker? idk

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

View File

@ -1,6 +1,8 @@
function Walk(obj)
{
const set = new Set();
function Walk(obj, parentObject, propertyName, path=[])
function Step(obj, path="")
{
if(obj !== null && typeof obj === "object")
{
@ -17,18 +19,21 @@ function Walk(obj, parentObject, propertyName, path=[])
for(let key in obj)
{
const val = obj[key];
console.log(key, val);
Walk(val, obj, key);
console.log(" >stepping into", path+"."+key);
Step(val, path+"."+key);
}
console.log("-----------------");
}
}
else
{
console.log(obj, "is a leaf")
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);