Created
December 4, 2019 17:51
-
-
Save baldmountain/4fd9272491b2f10dde1d962742ad87ef to your computer and use it in GitHub Desktop.
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
const testFunction = () => { | |
let propertiesA = {a: 1, b: 'A', c: 5, config: {a: 2}}; | |
let propertiesB = {a: 2, d: 4, f: 6, person: 'Tom', config: {a:5, b: 10}}; | |
let newObject = coolfunction(propertiesA, propertiesB) | |
return coolfunction(objA, objB); | |
}; | |
function coolfunction(objA, objB) { | |
let s, next, empty = {}; | |
for (let name in objB) { | |
s = objB[name]; | |
if (!(name in objA) || (objA[name] !== s && (!(name in empty) || empty[name] !== s))) { | |
if (typeof s === 'object' && !(s instanceof Array) && s !== null) { | |
if (!(name in objA) || !objA[name]) { | |
objA[name] = {}; | |
} | |
coolfunction(objA[name], s); | |
} else { | |
objA[name] = s; | |
} | |
} | |
} | |
return objA | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment