Skip to content

Instantly share code, notes, and snippets.

@basarat
Last active January 18, 2016 16:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save basarat/43b841abc6cfe6db1271 to your computer and use it in GitHub Desktop.
Save basarat/43b841abc6cfe6db1271 to your computer and use it in GitHub Desktop.
export function extend(...args: any[]):any {
var extendRecursive = (x:any[], extractFields:(y)=>void) => {
for (let obj of x) {
if (obj) {
if (obj instanceof Array) {
extendRecursive(obj, extractFields)
}
else {
extractFields(obj);
}
}
}
}
let newObj = {};
extendRecursive(args, obj => {
for (let key in obj) {
//copy all the fields
newObj[key] = obj[key];
}
});
return newObj;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment