Skip to content

Instantly share code, notes, and snippets.

@postpostscript
Last active March 23, 2023 18:28
Show Gist options
  • Save postpostscript/20504151ef9dcc3d473ab45168f2c64c to your computer and use it in GitHub Desktop.
Save postpostscript/20504151ef9dcc3d473ab45168f2c64c to your computer and use it in GitHub Desktop.
deepExtend.js
function deepExtend(base, arg) {
const baseType = typeof base
const argType = typeof arg
if (baseType !== argType || baseType !== 'object' || arg instanceof Array) {
return arg
}
return Object.fromEntries([
...Object.entries(base),
...Object.entries(arg).map(([key, value]) => {
return [
key,
deepExtend(base[key], value),
]
}),
])
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment