I have an array objects of market ticks with the following values:
candles['AUDIOUSDT'] = [
{
t: 1649936820000,
o: 41044.99,
c: 41052.21,
h: 41063.84,
l: 41044.99,
v: 1.2067
},
{
t: 1649936820000,
o: 41044.99,
c: 41045,
h: 41063.84,
l: 41044.99,
v: 1.3728
},
{
t: 1649936880000,
o: 41044.99,
c: 41045,
h: 41063.84,
l: 41044.99,
v: 0.1
},
{
t: 1649936880000,
o: 41044,
c: 41049,
h: 41049,
l: 41011,
v: 1
}
]
and I would like to have last time of each time in array object:
candles['AUDIOUSDT'] = [
{
t: 1649936820000,
o: 41060.01,
c: 41045,
h: 41063.84,
l: 41044.99,
v: 1.3728
},
{
t: 1649936880000,
o: 41044,
c: 41049,
h: 41049,
l: 41011,
v: 1
}
Basically, I want to merge values if t, o, c, h, l, v which are the same time, any ideas on how to elegantly do this?
Thanks in advance
So, it just requires you to do a backwards loop and check if the "t" value is already in a unique times list. If it is, it will skip it, else it will add the entire object to a new
uniques
array which holds the results.