Created
April 4, 2018 05:52
-
-
Save mtranter/d1c81c1ccb972a1ecd6e7eb06875fcec to your computer and use it in GitHub Desktop.
Like Object.assign. But deep.
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 deepAssign = (target, ...sources) => | |
sources.reduce((total, src) => | |
Object.keys(src).reduce((agg, n) => | |
Object.assign({}, agg, { | |
[n]: ( | |
typeof src[n] === "object" ? | |
deepAssign(target[n] || {}, src[n]) : | |
src[n] | |
) | |
}), | |
total), | |
target) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment