Created
February 16, 2018 15:50
-
-
Save joelcolucci/f28d004b6726a9bcc506650874062265 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @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