Last active
May 18, 2018 05:15
-
-
Save cenkce/34b087f3cdd04139339a9d9eb02cc5f7 to your computer and use it in GitHub Desktop.
Deeply object merge
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
function isObj(val){ | |
return val !== null && typeof val === "object"; | |
} | |
function recurse(acc, obj){ | |
for (var p in obj) { | |
acc[p] = isObj(obj[p]) ? recurse(acc[p] || {}, obj[p]) : obj[p]; | |
} | |
return acc; | |
} | |
export default function deepMerge() { | |
var args = Array.prototype.slice.call(arguments); | |
return args.reduce(recurse, {}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment