Created
November 13, 2018 11:56
-
-
Save hn3000/9de694e80f9a34e6d95657ddca5a7cda to your computer and use it in GitHub Desktop.
shallow merge, one of my favourites
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
function shallowMerge(a:any, b:any):any { | |
let result:any = {}; | |
let tmp:any = {}; | |
Object.keys(a).forEach((x) => tmp[x]=x); | |
Object.keys(b).forEach((x) => tmp[x]=x); | |
let keys = Object.keys(tmp); | |
for (var k of keys) { | |
result[k] = null != b[k] ? b[k] : a[k]; | |
} | |
return result; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment