I have a list of dictionaries like this that may contain duplicates based on a few dictionary properties (not all properties):
const data = [{
name: 'v',
latitude: '30.0',
longitude: '25.0'
}, {
name: 'w',
latitude: '30.0',
longitude: '25.0'
}, {
name: 'x',
latitude: '45.9',
longitude: '50.2'
}, {
name: 'y',
latitude: '40.5',
longitude: '85.7'
}, {
name: 'z',
latitude: '40.5',
longitude: '85.7'
}];
Here, two dictionaries are considered duplicates if they share the same longitude and latitude.
The goal is to reduce this 1D list, grouping all duplicates of one kind into a nested list. For example, if we have three duplicates with the same coordinates, they should go into their own nested list, whereas two duplicates of another coordinate go into a different nested list. Even a standalone coordinate with no duplicates should go into its own nested list. We want to end up with a list where every item is a list that represents a unique coordinate.
Desired output:
[
[
{
name: 'v',
latitude: '30.0',
longitude: '25.0'
}, {
name: 'w',
latitude: '30.0',
longitude: '25.0'
}
],
[
{
name: 'x',
latitude: '45.9',
longitude: '50.2'
}
],
[
{
name: 'y',
latitude: '40.5',
longitude: '85.7'
}, {
name: 'z',
latitude: '40.5',
longitude: '85.7'
}
]
];
EDIT: Corrected desired output so that all items are lists.