Last active
July 21, 2021 07:03
-
-
Save SephReed/f122734baebf4c62f8302222b5ef0308 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 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