Skip to content

Instantly share code, notes, and snippets.

@SephReed
Last active July 21, 2021 07:03
Show Gist options
  • Save SephReed/f122734baebf4c62f8302222b5ef0308 to your computer and use it in GitHub Desktop.
Save SephReed/f122734baebf4c62f8302222b5ef0308 to your computer and use it in GitHub Desktop.
const eg = smoosh([
{ foo: {a: 1}},
{ foo: {b: 2}}
]);
eg.foo.a
eg.foo.b
// take an array of objects, do your best to smoosh them together
function smoosh(objs) {
let out = {};
Object.entries(objs).forEach(([key, value]) => {
if (typeof value === "object" && out[key]) {
out[key] = smoosh([out[key], value]);
} else {
out[key] = value;
}
})
return out;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment