Last active
August 29, 2015 13:55
-
-
Save lionelB/8689549 to your computer and use it in GitHub Desktop.
flatten object hierarchy. Rely on (underscore|lodash).js - Object's keys with the same name will be overwritten
This file contains hidden or 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
_.reduce(o, function red(memo, val, key){ | |
if(typeof val === 'object'){ | |
_.reduce(val, red, memo) | |
} else { | |
memo[key] = val; | |
} | |
return memo; | |
}, Object.create(null)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
my take on this one (to prevent overwrites)