Skip to content

Instantly share code, notes, and snippets.

@anfedorov
Created November 30, 2009 16:38
Show Gist options
  • Save anfedorov/245541 to your computer and use it in GitHub Desktop.
Save anfedorov/245541 to your computer and use it in GitHub Desktop.
function I(x) { return x; }
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(obj[k], pre, post));
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