Created
April 16, 2019 13:42
-
-
Save DimaCrafter/8d490dd5291c63e16e8a118a4ac02135 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
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