I'm trying to remove duplicates from a nested array of objects.
let arr = [{
type: "horizontal",
tiles: [{ col: 0, row: 3 }, { col: 1, row: 3 }, { col: 2, row: 3 }]
},
{
type: "horizontal",
tiles: [{ col: 1, row: 3 }, { col: 2, row: 3 }, { col: 0, row: 3 }]
},
{
type: "horizontal",
tiles: [{ col: 2, row: 3 }, { col: 1, row: 3 }, { col: 0, row: 3 }],
},
{
type: "vertical",
tiles: [{ col: 0, row: 5 }, { col: 0, row: 3 }, { col: 0, row: 4 }],
}];
I'm trying to only keep the top level objects if they are unique. As you can see the tiles array isn't necessarily sorted by col/row.
So arr
here would become:
let arr = [{
type: "horizontal",
tiles: [{ col: 0, row: 3 }, { col: 1, row: 3 }, { col: 2, row: 3 }]
},{
type: "vertical",
tiles: [{ col: 0, row: 5 }, { col: 0, row: 3 }, { col: 0, row: 4 }],
}];
I've looked extensively but can't quite find something that solves the same problem I'm trying to solve.