Skip to content

Instantly share code, notes, and snippets.

@anfedorov
Created November 7, 2009 09:35
Show Gist options
  • Save anfedorov/228629 to your computer and use it in GitHub Desktop.
Save anfedorov/228629 to your computer and use it in GitHub Desktop.
function walk(obj, pre, post) {
var k, v;
obj = (pre||I)(obj);
if (typeof(obj) === 'object') {
for (k in obj) if (obj.hasOwnProperty(k)) {
v = (post||I)(walk(k));
if (v === undefined) {
delete obj[k];
} else {
obj[k] = v;
}
}
}
return obj;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment