Let's explore this collection of objects:
[
{
key1: "AAA",
key2: "BBB"
},
{
key1: "BBB",
key2: "CCC"
},
{
key1: "CCC",
key2: "DDD"
},
{
key1: "XXX",
key2: "YYY"
},
]
How can we create a simple function to group these objects in a way that if the key1
of the next object matches the key2
of the previous one, they are combined into a single object?
The expected result from the above set of objects would be:
[
{
key1: "AAA",
key2: "DDD"
},
{
key1: "XXX",
key2: "YYY"
},
]