Skip to content

Instantly share code, notes, and snippets.

@cenkce
Last active May 18, 2018 05:15
Show Gist options
  • Save cenkce/34b087f3cdd04139339a9d9eb02cc5f7 to your computer and use it in GitHub Desktop.
Save cenkce/34b087f3cdd04139339a9d9eb02cc5f7 to your computer and use it in GitHub Desktop.
Deeply object merge
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