Skip to content

Instantly share code, notes, and snippets.

@bjconlan
Last active February 2, 2022 16:10
Show Gist options
  • Save bjconlan/e53c2eb4b4d811899d7ba9dc265ee949 to your computer and use it in GitHub Desktop.
Save bjconlan/e53c2eb4b4d811899d7ba9dc265ee949 to your computer and use it in GitHub Desktop.
Additive merge
const merge = (l, r) => Array.isArray(l) ? [...l, ...r]
: l?.constructor === Object ? [...Object.entries(l), ...Object.entries(r)].reduce((r, [k, v]) => {
r[k] = r[k] == null ? v : merge(r[k], v);
return r;
}, {})
: r;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment