I am working on generating tax reports based off an array of orders. Essentially I need to convert the following array:
[
{
"rate": 6.75,
"code": "US-NC-Guilford-27409",
"grand": 39.981625,
"tax": 2.02
},
{
"rate": 7.5,
"code": "US-NC-Orange-27516",
"grand": 186.25,
"tax": 11.25
},
{
"rate": 7.5,
"code": "US-NC-Orange-27516",
"grand": 29.19625,
"tax": 1.5
}
]
Into separate arrays of each class "code", where the classes "codes" could equal anything, and could have any number of that type. So it would look something like this:
[
US-NC-Guilford-27409:[
{
"rate":6.75,
"code":"US-NC-Guilford-27409",
"grand":39.981625,
"tax":2.02
}
],
US-NC-Orange-27516:[
{
"rate":7.5,
"code":"US-NC-Orange-27516",
"grand":186.25,
"tax":11.25
},
{
"rate":7.5,
"code":"US-NC-Orange-27516",
"grand":29.19625,
"tax":1.5
}
]
]
But I'm completely open to other ways of formatting the separated data, but for when the report is generated we have to give a log of orders from each tax class.
So how would you create that output using JavaScript (Node)?