Skip to content

Instantly share code, notes, and snippets.

@hn3000
Created November 13, 2018 11:56
Show Gist options
  • Save hn3000/9de694e80f9a34e6d95657ddca5a7cda to your computer and use it in GitHub Desktop.
Save hn3000/9de694e80f9a34e6d95657ddca5a7cda to your computer and use it in GitHub Desktop.
shallow merge, one of my favourites
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