Skip to content

Instantly share code, notes, and snippets.

@marcustyphoon
Created August 13, 2023 07:07
Show Gist options
  • Save marcustyphoon/6d7246827c225fe700ec09769127cbdc to your computer and use it in GitHub Desktop.
Save marcustyphoon/6d7246827c225fe700ec09769127cbdc to your computer and use it in GitHub Desktop.
const isObject = (value) => value && typeof value === 'object' && !Array.isArray(value);
const deepMerge = (a, b) => {
const result = { ...a };
Object.keys(b).forEach((key) => {
if (isObject(a[key]) && isObject(b[key])) {
result[key] = deepMerge(a[key], b[key]);
} else {
result[key] = b[key];
}
});
return result;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment