When receiving data from an API, it may look something like this:
"stats": [
{
"label": 2016,
"stats": {
"return": 4,
"stddev": 4,
"sharpe": 4,
"maxddown": 4
}
},
{
"label": 2015,
"stats": {
"return": 5,
"stddev": 5,
"sharpe": 5,
"maxddown": 5
}
},
{
"label": 2014,
"stats": {
"return": 6,
"stddev": 6,
"sharpe": 6,
"maxddown": 6
}
}
]
There is a need to transform this data into an array of objects for rendering a table in an Ember app. However, the process of transforming the data can be challenging. The desired format for the table data should be as follows:
const tableData = [
{
name: 'return',
2016: 4,
2015: 5,
2014: 6
}, {
name: 'stddev',
2016: 4,
2015: 5,
2014: 6
}, {
name: 'sharpe',
2016: 4,
2015: 5,
2014: 6
}, {
name: 'maxddown',
2016: 4,
2015: 5,
2014: 6
}
]