My problem is pretty straight forward I think, I just can't seem to figure it out. I need to go from an array of objects:
let testArrays = [
{ "containerType": "2 Gallon", "wasteType": "10000001", "vol": "2 Gallons" },
{ "containerType": "2 Gallon", "wasteType": "10000001", "vol": "2 Gallons" },
{ "containerType": "2 Gallon", "wasteType": "10000002", "vol": "2 Gallons" },
{ "containerType": "2 Gallon", "wasteType": "10000002", "vol": "2 Gallons" },
{ "containerType": "2 Gallon", "wasteType": "10000003", "vol": "2 Gallons" },
{ "containerType": "5 Gallon", "wasteType": "10000003", "vol": "5 Gallons" },
{ "containerType": "5 Gallon", "wasteType": "10000003", "vol": "5 Gallons" },
{ "containerType": "5 Gallon", "wasteType": "10000003", "vol": "5 Gallons" },
{ "containerType": "5 Gallon", "wasteType": "10000004", "vol": "5 Gallons" }
]
To a grouped object with arrays inside, grouped by "wasteType" above with counts. The volume would be created by multiplying the count by the value in "vol", which I can get with parsefloat I believe :
let wastes = {
"10000001": [
{
"containerType": "2 Gallon",
"count": 2,
"vol": "4 Gallons"
}
],
"10000002": [
{
"containerType": "2 Gallon",
"count": 2,
"vol": "4 Gallons"
}
],
"10000003": [
{
"containerType": "1 Gallon",
"count": 1,
"vol": "2 Gallons"
},
{
"containerType": "5 Gallon",
"count": 3,
"vol": "15 Gallons"
}
],
"10000004": [
{
"containerType": "5 Gallon",
"count": 1,
"vol": "5 Gallons"
}
],
}
I know I should use array.map() for this but I am not sure how to do it. I have looked for this specific example everywhere and can't find it. All help is greatly appreciated.