Skip to content

Instantly share code, notes, and snippets.

@joelcolucci
Created February 16, 2018 15:50
Show Gist options
  • Save joelcolucci/f28d004b6726a9bcc506650874062265 to your computer and use it in GitHub Desktop.
Save joelcolucci/f28d004b6726a9bcc506650874062265 to your computer and use it in GitHub Desktop.
/**
* @param {*} value
* @return {*}
*/
function dfsEval(value) {
// Base case if not object
if (!isObject(value)) {
if (isFunction(value)) {
return value();
} else {
return value;
}
}
// Recursive case - reduce the problem
let result = {};
for (let key in value) {
if (value.hasOwnProperty(key)) {
result[key] = dfsEval(value[key]);
}
}
return result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment