Skip to content

Instantly share code, notes, and snippets.

@danielrw7
Last active March 23, 2023 18:28
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 danielrw7/20504151ef9dcc3d473ab45168f2c64c to your computer and use it in GitHub Desktop.
Save danielrw7/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