Last active
February 2, 2022 16:10
-
-
Save bjconlan/e53c2eb4b4d811899d7ba9dc265ee949 to your computer and use it in GitHub Desktop.
Additive merge
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 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