Skip to content

Instantly share code, notes, and snippets.

@DimaCrafter
Created April 16, 2019 13:42
Show Gist options
  • Save DimaCrafter/8d490dd5291c63e16e8a118a4ac02135 to your computer and use it in GitHub Desktop.
Save DimaCrafter/8d490dd5291c63e16e8a118a4ac02135 to your computer and use it in GitHub Desktop.
function assign (obj1, obj2) {
if (!obj1) return obj2;
if (!obj2) return obj1;
let result = {};
for (let key in obj1) {
if (key in obj2) {
if (typeof obj2[key] == 'object') result[key] = assign(obj1[key], obj2[key]);
else result[key] = obj2[key];
} else result[key] = obj1[key];
}
for (let key in obj2) {
if (!result[key]) result[key] = obj2[key];
}
return result;
}
module.exports = assign;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment