walker started

This commit is contained in:
Seth Trowbridge 2025-02-25 15:46:03 -05:00
parent 06ee58439a
commit cec0803aff

34
walker.js Normal file
View File

@ -0,0 +1,34 @@
const set = new Set();
function Walk(obj, parentObject, propertyName, path=[])
{
if(obj !== null && typeof obj === "object")
{
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(key, val);
Walk(val, obj, key);
}
console.log("-----------------");
}
}
else
{
console.log(obj, "is a leaf")
}
}
const root = {hey:"1", deep:{}, arr:["a", "b"]};
root.circ = root;
Walk(root);