I have an array with the following values:
let orders = [
{n: 0, orderId: null, lat: 49.396315, lng: 15.609607, type: "start"},
{n: 2.5, orderId: 26889, lat: 48.98951, lng: 14.45937, type: "odes"},
{n: 9, orderId: 26969, lat: 50.0823536, lng: 12.3791268, type: "odes"},
{n: 9, orderId: 26995, lat: 50.0823536, lng: 12.3791268, type: "odes"},
{n: 31, orderId: null, lat: 50.7343366, lng: 15.0501002, type: "end"},
{n: 31, orderId: 26969, lat: 50.7343366, lng: 15.0501002, type: "prij"},
{n: 31, orderId: 26995, lat: 50.7343366, lng: 15.0501002, type: "prij"},
];
and I would like to have following result:
[
{n: 0, orderId: null, lat: 49.396315, lng: 15.609607, type: "start"},
{n: 2.5, orderId: 26889, lat: 48.98951, lng: 14.45937, type: "odes"},
{n: 9, orderId: [26969,26995], lat: 50.0823536, lng: 12.3791268, type: ["odes", "odes"]},
{n: 31, orderId: [null,26969,26995], lat: 50.7343366, lng: 15.0501002, type: ["end", "prij", "prij"]},
]
Basically, I want to merge values if n, lat and long are the same,
any ideas on how to elegantly do this?
Thanks in advance
ordersand set a new one ?