Skip to content

Instantly share code, notes, and snippets.

@baldmountain
Created December 4, 2019 17:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save baldmountain/4fd9272491b2f10dde1d962742ad87ef to your computer and use it in GitHub Desktop.
Save baldmountain/4fd9272491b2f10dde1d962742ad87ef to your computer and use it in GitHub Desktop.
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