Medium
How to Group and Calculate Daily Averages from Time Series Data using JavaScript Reduce
In a data visualization dashboard, you need to transform raw time series data into a format suitable for charting. Fill in the missing transformation code that correctly groups and aggregates the data by date:
1const rawData = [2 { timestamp: '2024-01-01T02:30:00Z', value: 10 },3 { timestamp: '2024-01-01T03:45:00Z', value: 15 },4 { timestamp: '2024-01-01T15:20:00Z', value: 25 },5 { timestamp: '2024-01-02T04:15:00Z', value: 30 },6 { timestamp: '2024-01-02T16:45:00Z', value: 20 }7];89function transformTimeSeriesData(data) {10 // Group by date and calculate daily average11 return ______________;12}1314// Expected output:15// {16// '2024-01-01': 16.67, // Average of 10, 15, and 2517// '2024-01-02': 25 // Average of 30 and 2018// }