Created
August 13, 2023 07:07
-
-
Save marcustyphoon/6d7246827c225fe700ec09769127cbdc 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
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