I have a basic JSON list provided below:
{
"myList": [
{
"endOfPeriod": 1461362400000,
"rate": 0.03726378
},
{
"endOfPeriod": 1461535200000,
"rate": 0.03726378
},
{
"endOfPeriod": 1461967200000,
"rate": 0.03708314
},
{
"endOfPeriod": 1461708000000,
"rate": 0.03492851
},
{
"endOfPeriod": 1461794400000,
"rate": 0.03845068
},
{
"endOfPeriod": 1461621600000,
"rate": 0.03544827
}
]
}
In this example, the endOfPeriod
value is represented as a Unix epoch timestamp. Although all the timestamps in the sample data correspond to April 2016, they could belong to other time periods as well.
Assuming that I have already converted this JSON list into an array and transformed each Unix timestamp into a DD.MM.YYYY
date format (or kept them as Unix timestamps), I need to find an effective method to create a new array containing the most recent rate for each month/year group.
The task requires writing JavaScript code.
For instance:
20.04.2016 / 0.33
21.04.2016 / 0.55
14.04.2016 / 0.88
02.05.2016 / 1.33
01.05.2016 / 5.44
The resulting array should include:
21.04.2016 / 0.55
02.05.2016 / 1.33
Thank you for your assistance.