Всем привет, подскажите, как более оптимально отфильтровать данные:
const data = [
{
"date": "2020-03-02",
"value": "-0.00807736"
},
{
"date": "2020-03-03",
"value": "0.01775831"
},
{
"date": "2020-03-04",
"value": "0.00433390"
},
{
"date": "2020-03-31",
"value": "0.02667099"
},
{
"date": "2020-04-01",
"value": "-0.01370213"
},
{
"date": "2020-04-02",
"value": "0.02922457"
},
{
"date": "2020-04-03",
"value": "0.01015846"
},
{
"date": "2020-04-06",
"value": "0.01984755"
},
{
"date": "2020-04-07",
"value": "0.00296561"
},
{
"date": "2020-04-08",
"value": "0.01393626"
},
{
"date": "2020-04-09",
"value": "0.01132951"
},
{
"date": "2020-04-10",
"value": "-0.00822985"
},
{
"date": "2020-04-13",
"value": "-0.01640604"
},
{
"date": "2020-05-04",
"value": "-0.00000651"
},
{
"date": "2020-05-05",
"value": "-0.00000513"
},
{
"date": "2020-05-06",
"value": "-0.00501929"
},
{
"date": "2020-05-07",
"value": "0.00339571"
},
{
"date": "2020-05-08",
"value": "0.00176003"
}
]
/*
output
[
2020-03-02,
2020-04-01,
2020-05-04,
]
*/
const filtered = (data) => Object.values(data.reduceRight((accumulator, currentValue) => {
accumulator[new Date(currentValue.date).getMonth()] = currentValue.date
return accumulator
}, {}))
console.log(filtered(data));